162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci#ifndef _TOOLS_ASM_BUG_H 362306a36Sopenharmony_ci#define _TOOLS_ASM_BUG_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/compiler.h> 662306a36Sopenharmony_ci#include <stdio.h> 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#define __WARN_printf(arg...) do { fprintf(stderr, arg); } while (0) 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#define WARN(condition, format...) ({ \ 1162306a36Sopenharmony_ci int __ret_warn_on = !!(condition); \ 1262306a36Sopenharmony_ci if (unlikely(__ret_warn_on)) \ 1362306a36Sopenharmony_ci __WARN_printf(format); \ 1462306a36Sopenharmony_ci unlikely(__ret_warn_on); \ 1562306a36Sopenharmony_ci}) 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#define WARN_ON(condition) ({ \ 1862306a36Sopenharmony_ci int __ret_warn_on = !!(condition); \ 1962306a36Sopenharmony_ci if (unlikely(__ret_warn_on)) \ 2062306a36Sopenharmony_ci __WARN_printf("assertion failed at %s:%d\n", \ 2162306a36Sopenharmony_ci __FILE__, __LINE__); \ 2262306a36Sopenharmony_ci unlikely(__ret_warn_on); \ 2362306a36Sopenharmony_ci}) 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#define WARN_ON_ONCE(condition) ({ \ 2662306a36Sopenharmony_ci static int __warned; \ 2762306a36Sopenharmony_ci int __ret_warn_once = !!(condition); \ 2862306a36Sopenharmony_ci \ 2962306a36Sopenharmony_ci if (unlikely(__ret_warn_once && !__warned)) { \ 3062306a36Sopenharmony_ci __warned = true; \ 3162306a36Sopenharmony_ci WARN_ON(1); \ 3262306a36Sopenharmony_ci } \ 3362306a36Sopenharmony_ci unlikely(__ret_warn_once); \ 3462306a36Sopenharmony_ci}) 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#define WARN_ONCE(condition, format...) ({ \ 3762306a36Sopenharmony_ci static int __warned; \ 3862306a36Sopenharmony_ci int __ret_warn_once = !!(condition); \ 3962306a36Sopenharmony_ci \ 4062306a36Sopenharmony_ci if (unlikely(__ret_warn_once)) \ 4162306a36Sopenharmony_ci if (WARN(!__warned, format)) \ 4262306a36Sopenharmony_ci __warned = 1; \ 4362306a36Sopenharmony_ci unlikely(__ret_warn_once); \ 4462306a36Sopenharmony_ci}) 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#endif /* _TOOLS_ASM_BUG_H */ 47