119c468b4SFrançois Tigeot /* 219c468b4SFrançois Tigeot * Copyright (c) 2016 François Tigeot 319c468b4SFrançois Tigeot * All rights reserved. 419c468b4SFrançois Tigeot * 519c468b4SFrançois Tigeot * Redistribution and use in source and binary forms, with or without 619c468b4SFrançois Tigeot * modification, are permitted provided that the following conditions 719c468b4SFrançois Tigeot * are met: 819c468b4SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright 919c468b4SFrançois Tigeot * notice unmodified, this list of conditions, and the following 1019c468b4SFrançois Tigeot * disclaimer. 1119c468b4SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright 1219c468b4SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the 1319c468b4SFrançois Tigeot * documentation and/or other materials provided with the distribution. 1419c468b4SFrançois Tigeot * 1519c468b4SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1619c468b4SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1719c468b4SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1819c468b4SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1919c468b4SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2019c468b4SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2119c468b4SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2219c468b4SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2319c468b4SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2419c468b4SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2519c468b4SFrançois Tigeot */ 2619c468b4SFrançois Tigeot 2719c468b4SFrançois Tigeot #ifndef _ASM_BUG_H_ 2819c468b4SFrançois Tigeot #define _ASM_BUG_H_ 2919c468b4SFrançois Tigeot 30*742b09c6Szrj #include <sys/param.h> 31*742b09c6Szrj #include <linux/kernel.h> 32*742b09c6Szrj 33*742b09c6Szrj #define BUG() do \ 34*742b09c6Szrj { \ 35*742b09c6Szrj panic("BUG in %s at %s:%u", \ 36*742b09c6Szrj __func__, __FILE__, __LINE__); \ 37*742b09c6Szrj } while (0) 38*742b09c6Szrj 39*742b09c6Szrj #define BUG_ON(condition) do { if (condition) BUG(); } while(0) 40*742b09c6Szrj 4119c468b4SFrançois Tigeot #define _WARN_STR(x) #x 4219c468b4SFrançois Tigeot 4319c468b4SFrançois Tigeot #define WARN_ON(condition) ({ \ 4419c468b4SFrançois Tigeot int __ret = !!(condition); \ 4519c468b4SFrançois Tigeot if (__ret) \ 4619c468b4SFrançois Tigeot kprintf("WARNING %s failed at %s:%d\n", \ 4719c468b4SFrançois Tigeot _WARN_STR(condition), __FILE__, __LINE__); \ 4819c468b4SFrançois Tigeot unlikely(__ret); \ 4919c468b4SFrançois Tigeot }) 5019c468b4SFrançois Tigeot 51*742b09c6Szrj #ifndef WARN 52*742b09c6Szrj #define WARN(condition, format...) ({ \ 53*742b09c6Szrj int __ret_warn_on = !!(condition); \ 54*742b09c6Szrj if (unlikely(__ret_warn_on)) \ 55*742b09c6Szrj pr_warning(format); \ 56*742b09c6Szrj unlikely(__ret_warn_on); \ 57*742b09c6Szrj }) 58*742b09c6Szrj #endif 59*742b09c6Szrj 6019c468b4SFrançois Tigeot #define WARN_ON_ONCE(condition) ({ \ 6119c468b4SFrançois Tigeot static int __warned; \ 6219c468b4SFrançois Tigeot int __ret = !!(condition); \ 6319c468b4SFrançois Tigeot if (__ret && !__warned) { \ 6419c468b4SFrançois Tigeot kprintf("WARNING %s failed at %s:%d\n", \ 6519c468b4SFrançois Tigeot _WARN_STR(condition), __FILE__, __LINE__); \ 6619c468b4SFrançois Tigeot __warned = 1; \ 6719c468b4SFrançois Tigeot } \ 6819c468b4SFrançois Tigeot unlikely(__ret); \ 6919c468b4SFrançois Tigeot }) 7019c468b4SFrançois Tigeot 71*742b09c6Szrj #define WARN_ONCE(condition, format...) ({ \ 72*742b09c6Szrj static bool __warned_once; \ 73*742b09c6Szrj int __ret = !!(condition); \ 74*742b09c6Szrj \ 75*742b09c6Szrj if ((condition) && !__warned_once) { \ 76*742b09c6Szrj WARN(condition, format); \ 77*742b09c6Szrj __warned_once = true; \ 78*742b09c6Szrj } \ 79*742b09c6Szrj unlikely(__ret); \ 80*742b09c6Szrj }) 81*742b09c6Szrj 8219c468b4SFrançois Tigeot #define WARN_ON_SMP(condition) WARN_ON(condition) 8319c468b4SFrançois Tigeot 8419c468b4SFrançois Tigeot #endif /* _ASM_BUG_H_ */ 85