bug.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_GENERIC_BUG_H
  3. #define _ASM_GENERIC_BUG_H
  4. #include "printk.h"
  5. #include "build_bug.h"
  6. #include "linux/compiler.h"
  7. #ifndef WARN
  8. #define WARN(condition, format...) \
  9. ({ \
  10. int __ret_warn_on = !!(condition); \
  11. if (unlikely(__ret_warn_on)) { \
  12. efi_warn("(%s:%d)", __FILE__, __LINE__); \
  13. efi_printk(format); \
  14. } \
  15. unlikely(__ret_warn_on); \
  16. })
  17. #endif
  18. #ifndef WARN_ON
  19. #define WARN_ON(condition) \
  20. ({ \
  21. int __ret_warn_on = !!(condition); \
  22. if (unlikely(__ret_warn_on)) \
  23. efi_warn("(%s:%d)\n", __FILE__, __LINE__); \
  24. unlikely(__ret_warn_on); \
  25. })
  26. #endif
  27. #define WARN_ON_ONCE(condition) WARN_ON(condition)
  28. #define WARN_ONCE(condition, format...) WARN(condition, format)
  29. #define WARN_TAINT(condition, taint, format...) WARN(condition, format)
  30. #define WARN_TAINT_ONCE(condition, taint, format...) WARN(condition, format)
  31. /* Optimization barrier */
  32. #ifndef barrier
  33. /* The "volatile" is due to gcc bugs */
  34. #define barrier() __asm__ __volatile__("" : : : "memory")
  35. #endif
  36. #define BUILD_BUG_ON(condition) \
  37. do { \
  38. efi_err("BUILD_BUG_ON(%s)\n", #condition); \
  39. while (1) \
  40. ; \
  41. } while (1)
  42. #ifdef __CHECKER__
  43. #define BUILD_BUG_ON_ZERO(e) (0)
  44. #else /* __CHECKER__ */
  45. /*
  46. * Force a compilation error if condition is true, but also produce a
  47. * result (of value 0 and type int), so the expression can be used
  48. * e.g. in a structure initializer (or where-ever else comma expressions
  49. * aren't permitted).
  50. */
  51. #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int : (-!!(e)); })))
  52. #endif /* __CHECKER__ */
  53. #endif