diff options
author | Martin Radev <martin.b.radev@gmail.com> | 2022-05-09 23:39:35 +0300 |
---|---|---|
committer | Will Deacon <will@kernel.org> | 2022-05-20 21:21:09 +0100 |
commit | 143ffa2221d38b9405ce89552363b76cf3f6915c (patch) | |
tree | 1385390a095c762acb99e528a3edc004cfe52154 | |
parent | bc77bf49df6e1e4ff095558cceb718293dd5b763 (diff) | |
download | kvmtool-143ffa2221d38b9405ce89552363b76cf3f6915c.tar.gz |
kvmtool: Add WARN_ONCE macro
Add a macro to enable to print a warning only once. This is
beneficial for cases where a warning could be helpful for
debugging, but still log pollution is preferred not to happen.
Reviewed-by: Alexandru Elisei <alexandru.elisei@arm.com>
Signed-off-by: Martin Radev <martin.b.radev@gmail.com>
Link: https://lore.kernel.org/r/20220509203940.754644-2-martin.b.radev@gmail.com
Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r-- | include/kvm/util.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/kvm/util.h b/include/kvm/util.h index d76568a7..b4945487 100644 --- a/include/kvm/util.h +++ b/include/kvm/util.h @@ -82,6 +82,16 @@ do { \ __ret_warn_on; \ }) +#define WARN_ONCE(condition, format, args...) ({ \ + static int __warned; \ + int __ret_warn_on = !!(condition); \ + if (!__warned && __ret_warn_on) { \ + __warned = 1; \ + pr_warning(format, args); \ + } \ + __ret_warn_on; \ +}) + #define MSECS_TO_USECS(s) ((s) * 1000) /* Millisecond sleep */ |