Re: [RFC PATCH] notifier: Return non-null when callback already registered
From: Peter Zijlstra
Date: Fri May 21 2021 - 07:14:17 EST
On Thu, May 20, 2021 at 10:20:33PM +0200, Borislav Petkov wrote:
> From: Borislav Petkov <bp@xxxxxxx>
>
> 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@xxxxxxx/
>
> Which is unnecessary.
>
> Return a non-null to signal that case so that callers can act
> accordingly.
>
> Signed-off-by: Borislav Petkov <bp@xxxxxxx>
> ---
> 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?