LKML Archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] notifier: Return non-null when callback already registered
@ 2021-05-20 20:20 Borislav Petkov
  2021-05-21 11:11 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2021-05-20 20:20 UTC (permalink / raw)
  To: X86 ML; +Cc: LKML

From: Borislav Petkov <bp@suse.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 a non-null to signal that case so that callers can act
accordingly.

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 kernel/notifier.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/notifier.c b/kernel/notifier.c
index 1b019cbca594..ff7a3198c5fc 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 1;
 		}
 		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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] notifier: Return non-null when callback already registered
  2021-05-20 20:20 [RFC PATCH] notifier: Return non-null when callback already registered Borislav Petkov
@ 2021-05-21 11:11 ` Peter Zijlstra
  2021-05-21 14:06   ` Borislav Petkov
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2021-05-21 11:11 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: X86 ML, LKML

On Thu, May 20, 2021 at 10:20:33PM +0200, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.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 a non-null to signal that case so that callers can act
> accordingly.
> 
> Signed-off-by: Borislav Petkov <bp@suse.de>
> ---
>  kernel/notifier.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/notifier.c b/kernel/notifier.c
> index 1b019cbca594..ff7a3198c5fc 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");

That should give a big clue^

> -			return 0;
> +			return 1;

How about -EBUSY here?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] notifier: Return non-null when callback already registered
  2021-05-21 11:11 ` Peter Zijlstra
@ 2021-05-21 14:06   ` Borislav Petkov
  0 siblings, 0 replies; 3+ messages in thread
From: Borislav Petkov @ 2021-05-21 14:06 UTC (permalink / raw)
  To: Peter Zijlstra; +Cc: X86 ML, LKML

On Fri, May 21, 2021 at 01:11:42PM +0200, Peter Zijlstra wrote:
> > @@ -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");
> 
> That should give a big clue^

Yah, the big cluebat... Was wondering whether to remove it, actually.
But then I'd need to audit all users whether they handle retval
properly. Sounds like a kernelnewbies project to me...

> > -			return 0;
> > +			return 1;
> 
> How about -EBUSY here?

Yah, anthing but 0.

But if we're gonna return -E things, -EEXIST looks like an even better
fit to me...

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-21 14:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 20:20 [RFC PATCH] notifier: Return non-null when callback already registered Borislav Petkov
2021-05-21 11:11 ` Peter Zijlstra
2021-05-21 14:06   ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).