1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 202dfc8d7SNamhyung Kim #ifndef _TOOLS_ASM_BUG_H 302dfc8d7SNamhyung Kim #define _TOOLS_ASM_BUG_H 402dfc8d7SNamhyung Kim 5741a0c59SNamhyung Kim #include <linux/compiler.h> 6*058bd857SJiri Olsa #include <stdio.h> 7741a0c59SNamhyung Kim 802dfc8d7SNamhyung Kim #define __WARN_printf(arg...) do { fprintf(stderr, arg); } while (0) 902dfc8d7SNamhyung Kim 1002dfc8d7SNamhyung Kim #define WARN(condition, format...) ({ \ 1102dfc8d7SNamhyung Kim int __ret_warn_on = !!(condition); \ 1202dfc8d7SNamhyung Kim if (unlikely(__ret_warn_on)) \ 1302dfc8d7SNamhyung Kim __WARN_printf(format); \ 1402dfc8d7SNamhyung Kim unlikely(__ret_warn_on); \ 1502dfc8d7SNamhyung Kim }) 1602dfc8d7SNamhyung Kim 17b246a9d2SMatthew Wilcox #define WARN_ON(condition) ({ \ 18b246a9d2SMatthew Wilcox int __ret_warn_on = !!(condition); \ 19b246a9d2SMatthew Wilcox if (unlikely(__ret_warn_on)) \ 20b246a9d2SMatthew Wilcox __WARN_printf("assertion failed at %s:%d\n", \ 21b246a9d2SMatthew Wilcox __FILE__, __LINE__); \ 22b246a9d2SMatthew Wilcox unlikely(__ret_warn_on); \ 23b246a9d2SMatthew Wilcox }) 24b246a9d2SMatthew Wilcox 25ebb9a9aeSMatthew Wilcox #define WARN_ON_ONCE(condition) ({ \ 26ebb9a9aeSMatthew Wilcox static int __warned; \ 27ebb9a9aeSMatthew Wilcox int __ret_warn_once = !!(condition); \ 28ebb9a9aeSMatthew Wilcox \ 29ebb9a9aeSMatthew Wilcox if (unlikely(__ret_warn_once && !__warned)) { \ 30ebb9a9aeSMatthew Wilcox __warned = true; \ 31ebb9a9aeSMatthew Wilcox WARN_ON(1); \ 32ebb9a9aeSMatthew Wilcox } \ 33ebb9a9aeSMatthew Wilcox unlikely(__ret_warn_once); \ 34ebb9a9aeSMatthew Wilcox }) 35ebb9a9aeSMatthew Wilcox 3602dfc8d7SNamhyung Kim #define WARN_ONCE(condition, format...) ({ \ 3702dfc8d7SNamhyung Kim static int __warned; \ 3802dfc8d7SNamhyung Kim int __ret_warn_once = !!(condition); \ 3902dfc8d7SNamhyung Kim \ 4002dfc8d7SNamhyung Kim if (unlikely(__ret_warn_once)) \ 4102dfc8d7SNamhyung Kim if (WARN(!__warned, format)) \ 4202dfc8d7SNamhyung Kim __warned = 1; \ 4302dfc8d7SNamhyung Kim unlikely(__ret_warn_once); \ 4402dfc8d7SNamhyung Kim }) 4502dfc8d7SNamhyung Kim 4602dfc8d7SNamhyung Kim #endif /* _TOOLS_ASM_BUG_H */ 47