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