diff mbox series

[v0,35/42] sh: Check notifier registration return value

Message ID 20211108101157.15189-36-bp@alien8.de (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Borislav Petkov Nov. 8, 2021, 10:11 a.m. UTC
From: Borislav Petkov <bp@suse.de>

Avoid homegrown notifier registration checks.

No functional changes.

Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: linux-sh@vger.kernel.org
---
 arch/sh/kernel/cpu/sh4a/setup-sh7724.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Geert Uytterhoeven Nov. 8, 2021, 1:31 p.m. UTC | #1
Hi Borislav,

On Mon, Nov 8, 2021 at 1:50 PM Borislav Petkov <bp@alien8.de> wrote:
> From: Borislav Petkov <bp@suse.de>
>
> Avoid homegrown notifier registration checks.
>
> No functional changes.
>
> Signed-off-by: Borislav Petkov <bp@suse.de>

Thanks for your patch!

> --- a/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
> +++ b/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
> @@ -1277,11 +1277,14 @@ static struct notifier_block sh7724_post_sleep_notifier = {
>
>  static int __init sh7724_sleep_setup(void)
>  {
> -       atomic_notifier_chain_register(&sh_mobile_pre_sleep_notifier_list,
> -                                      &sh7724_pre_sleep_notifier);
> +       if (atomic_notifier_chain_register(&sh_mobile_pre_sleep_notifier_list,
> +                                          &sh7724_pre_sleep_notifier))
> +               pr_warn("SH7724 pre-sleep notifier already registered\n");
> +
> +       if (atomic_notifier_chain_register(&sh_mobile_post_sleep_notifier_list,
> +                                          &sh7724_post_sleep_notifier))
> +               pr_warn("SH7724 pre-sleep notifier already registered\n");

Do you think these can actually fail?

>
> -       atomic_notifier_chain_register(&sh_mobile_post_sleep_notifier_list,
> -                                      &sh7724_post_sleep_notifier);
>         return 0;
>  }
>  arch_initcall(sh7724_sleep_setup);

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Borislav Petkov Nov. 8, 2021, 1:49 p.m. UTC | #2
On Mon, Nov 08, 2021 at 02:31:41PM +0100, Geert Uytterhoeven wrote:
> Do you think these can actually fail?

Hmm, maybe you missed the 0th message. Does this explain it:

https://lore.kernel.org/r/20211108101924.15759-1-bp@alien8.de

?

Thx.
Geert Uytterhoeven Nov. 8, 2021, 2:03 p.m. UTC | #3
Hi Borislav,

On Mon, Nov 8, 2021 at 2:49 PM Borislav Petkov <bp@alien8.de> wrote:
> On Mon, Nov 08, 2021 at 02:31:41PM +0100, Geert Uytterhoeven wrote:
> > Do you think these can actually fail?
>
> Hmm, maybe you missed the 0th message. Does this explain it:
>
> https://lore.kernel.org/r/20211108101924.15759-1-bp@alien8.de
>
> ?

Thanks, but that still doesn't explain why we need to add the check,
for something that IMHO cannot fail, in a caller that cannot do
anything in the very unlikely event that he call would ever start
to fail?

The clue is the addition of __must_check in "[PATCH v0 42/42] notifier:
Return an error when callback is already registered"
(https://lore.kernel.org/all/20211108101157.15189-43-bp@alien8.de/).

I'll reply to that one...

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Sergey Shtylyov Nov. 8, 2021, 2:48 p.m. UTC | #4
On 08.11.2021 13:11, Borislav Petkov wrote:

> From: Borislav Petkov <bp@suse.de>
> 
> Avoid homegrown notifier registration checks.
> 
> No functional changes.
> 
> Signed-off-by: Borislav Petkov <bp@suse.de>
> Cc: linux-sh@vger.kernel.org
> ---
>   arch/sh/kernel/cpu/sh4a/setup-sh7724.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7724.c b/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
> index 0d990ab1ba2a..8dfbb8149f66 100644
> --- a/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
> +++ b/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
> @@ -1277,11 +1277,14 @@ static struct notifier_block sh7724_post_sleep_notifier = {
>   
>   static int __init sh7724_sleep_setup(void)
>   {
> -	atomic_notifier_chain_register(&sh_mobile_pre_sleep_notifier_list,
> -				       &sh7724_pre_sleep_notifier);
> +	if (atomic_notifier_chain_register(&sh_mobile_pre_sleep_notifier_list,
> +					   &sh7724_pre_sleep_notifier))
> +		pr_warn("SH7724 pre-sleep notifier already registered\n");
> +
> +	if (atomic_notifier_chain_register(&sh_mobile_post_sleep_notifier_list,
> +					   &sh7724_post_sleep_notifier))
> +		pr_warn("SH7724 pre-sleep notifier already registered\n");

   s/pre/post/? :-)

>   
> -	atomic_notifier_chain_register(&sh_mobile_post_sleep_notifier_list,
> -				       &sh7724_post_sleep_notifier);
>   	return 0;
>   }
>   arch_initcall(sh7724_sleep_setup);

MBR, Sergey
diff mbox series

Patch

diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7724.c b/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
index 0d990ab1ba2a..8dfbb8149f66 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
@@ -1277,11 +1277,14 @@  static struct notifier_block sh7724_post_sleep_notifier = {
 
 static int __init sh7724_sleep_setup(void)
 {
-	atomic_notifier_chain_register(&sh_mobile_pre_sleep_notifier_list,
-				       &sh7724_pre_sleep_notifier);
+	if (atomic_notifier_chain_register(&sh_mobile_pre_sleep_notifier_list,
+					   &sh7724_pre_sleep_notifier))
+		pr_warn("SH7724 pre-sleep notifier already registered\n");
+
+	if (atomic_notifier_chain_register(&sh_mobile_post_sleep_notifier_list,
+					   &sh7724_post_sleep_notifier))
+		pr_warn("SH7724 pre-sleep notifier already registered\n");
 
-	atomic_notifier_chain_register(&sh_mobile_post_sleep_notifier_list,
-				       &sh7724_post_sleep_notifier);
 	return 0;
 }
 arch_initcall(sh7724_sleep_setup);