Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jun 2025 22:25:06 GMT
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: eabb9f600001 - main - gone_in: enforce printing only once
Message-ID:  <202506242225.55OMP6G3036086@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=eabb9f600001cc19943965b84d492936a5c59ebd

commit eabb9f600001cc19943965b84d492936a5c59ebd
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2025-06-24 22:23:53 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2025-06-24 22:23:53 +0000

    gone_in: enforce printing only once
    
    This allows to use this KPI not only in device attach methods, but also
    for syscalls and code that can be called multiple times at machine
    runtime.
    
    Reviewed by:            imp
    Differential Revision:  https://reviews.freebsd.org/D50784
---
 sys/sys/systm.h | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index 7a6edaef2cb8..c4e0aafac452 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -576,10 +576,22 @@ void _gone_in_dev(device_t dev, int major, const char *msg, ...)
 #else
 #define	__gone_ok(m, msg)
 #endif
-#define gone_in(major, msg, ...)		__gone_ok(major, msg) \
-	_gone_in(major, msg __VA_OPT__(,) __VA_ARGS__)
-#define gone_in_dev(dev, major, msg, ...)	__gone_ok(major, msg) \
-	_gone_in_dev(dev, major, msg __VA_OPT__(,) __VA_ARGS__)
+#define gone_in(major, msg, ...)	do {				\
+	static bool __read_mostly __gone_in_ ## __LINE__ = true;	\
+	__gone_ok(major, msg);						\
+	if (__predict_false(__gone_in_ ## __LINE__)) {			\
+		__gone_in_ ## __LINE__ = false;				\
+		_gone_in(major, msg __VA_OPT__(,) __VA_ARGS__);		\
+	}								\
+} while (0)
+#define gone_in_dev(dev, major, msg, ...)	do {			\
+	static bool __read_mostly __gone_in_ ## __LINE__ = true;	\
+	__gone_ok(major, msg);						\
+	if (__predict_false(__gone_in_ ## __LINE__)) {			\
+		__gone_in_ ## __LINE__ = false;				\
+		_gone_in_dev(dev, major, msg __VA_OPT__(,) __VA_ARGS__);\
+	}								\
+} while (0)
 
 #ifdef INVARIANTS
 #define	__diagused



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202506242225.55OMP6G3036086>