[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210604144102.13849-1-bp@alien8.de>
Date: Fri, 4 Jun 2021 16:41:02 +0200
From: Borislav Petkov <bp@...en8.de>
To: X86 ML <x86@...nel.org>
Cc: LKML <linux-kernel@...r.kernel.org>
Subject: [PATCH -v2] notifier: Return non-null when callback is already registered
From: Borislav Petkov <bp@...e.de>
The notifier registration routine doesn't return a proper error value
when a callback has already been registered, leading people to track
whether that regisration has happened at the call site:
https://lore.kernel.org/amd-gfx/20210512013058.6827-1-mukul.joshi@amd.com/
Which is unnecessary.
Return -EEXIST to signal that case so that callers can act accordingly.
Signed-off-by: Borislav Petkov <bp@...e.de>
---
kernel/notifier.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/notifier.c b/kernel/notifier.c
index 1b019cbca594..5a31bc9b24b4 100644
--- a/kernel/notifier.c
+++ b/kernel/notifier.c
@@ -25,7 +25,7 @@ static int notifier_chain_register(struct notifier_block **nl,
while ((*nl) != NULL) {
if (unlikely((*nl) == n)) {
WARN(1, "double register detected");
- return 0;
+ return -EEXIST;
}
if (n->priority > (*nl)->priority)
break;
@@ -134,7 +134,7 @@ static int notifier_call_chain_robust(struct notifier_block **nl,
*
* Adds a notifier to an atomic notifier chain.
*
- * Currently always returns zero.
+ * Returns 0 on success, !0 on error.
*/
int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
struct notifier_block *n)
@@ -235,7 +235,7 @@ NOKPROBE_SYMBOL(atomic_notifier_call_chain);
* Adds a notifier to a blocking notifier chain.
* Must be called in process context.
*
- * Currently always returns zero.
+ * Returns 0 on success, !0 on error.
*/
int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
struct notifier_block *n)
@@ -354,7 +354,7 @@ EXPORT_SYMBOL_GPL(blocking_notifier_call_chain);
* Adds a notifier to a raw notifier chain.
* All locking must be provided by the caller.
*
- * Currently always returns zero.
+ * Returns 0 on success, !0 on error.
*/
int raw_notifier_chain_register(struct raw_notifier_head *nh,
struct notifier_block *n)
@@ -425,7 +425,7 @@ EXPORT_SYMBOL_GPL(raw_notifier_call_chain);
* Adds a notifier to an SRCU notifier chain.
* Must be called in process context.
*
- * Currently always returns zero.
+ * Returns 0 on success, !0 on error.
*/
int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
struct notifier_block *n)
--
2.29.2
Powered by blists - more mailing lists