linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cristian Marussi <cristian.marussi@arm.com>
To: Borislav Petkov <bp@alien8.de>
Cc: LKML <linux-kernel@vger.kernel.org>, linux-crypto@vger.kernel.org
Subject: Re: [PATCH v0 39/42] crypto: ccree - check notifier registration return value
Date: Fri, 12 Nov 2021 18:32:33 +0000	[thread overview]
Message-ID: <20211112183233.GB6655@e120937-lin> (raw)
In-Reply-To: <20211108101157.15189-40-bp@alien8.de>

On Mon, Nov 08, 2021 at 11:11:54AM +0100, Borislav Petkov wrote:
> From: Borislav Petkov <bp@suse.de>
> 
> Avoid homegrown notifier registration checks.
> 
> No functional changes.
> 

Hi Borislav,

> Signed-off-by: Borislav Petkov <bp@suse.de>
> Cc: linux-crypto@vger.kernel.org
> ---
>  drivers/crypto/ccree/cc_fips.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/ccree/cc_fips.c b/drivers/crypto/ccree/cc_fips.c
> index 702aefc21447..de842da7d51c 100644
> --- a/drivers/crypto/ccree/cc_fips.c
> +++ b/drivers/crypto/ccree/cc_fips.c
> @@ -146,7 +146,9 @@ int cc_fips_init(struct cc_drvdata *p_drvdata)
>  	tasklet_init(&fips_h->tasklet, fips_dsr, (unsigned long)p_drvdata);
>  	fips_h->drvdata = p_drvdata;
>  	fips_h->nb.notifier_call = cc_ree_fips_failure;
> -	atomic_notifier_chain_register(&fips_fail_notif_chain, &fips_h->nb);
> +
> +	if (atomic_notifier_chain_register(&fips_fail_notif_chain, &fips_h->nb))
> +		pr_warn("Failure notifier already registered\n");
>  

Looking at the implementation of atomic_notifier_chain_register() and
its internal helper down below, I can see that atomic_notifier_chain_register()
ALWAYS return 0 (O_o) and anyway there is a WARN() in the notifiier core already
to alert of double registrations.

What is the aim of this patch ?
It's not clear from the commit message what are you trying to achieve.
Am I missing something ?
(Is it to circumvent some static checker to avoid this false positive ?
just guessing...)

Thanks,
Cristian

-----8<----------
static int notifier_chain_register(struct notifier_block **nl,
                struct notifier_block *n)
{
        while ((*nl) != NULL) {
                if (unlikely((*nl) == n)) {
                        WARN(1, "double register detected");
                        return 0;
                }
                if (n->priority > (*nl)->priority)
                        break;
                nl = &((*nl)->next);
        }
        n->next = *nl;
        rcu_assign_pointer(*nl, n);
        return 0;
}

/**
 *      atomic_notifier_chain_register - Add notifier to an atomic notifier chain
 *      @nh: Pointer to head of the atomic notifier chain
 *      @n: New entry in notifier chain
 *
 *      Adds a notifier to an atomic notifier chain.
 *
 *      Currently always returns zero.
 */
int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
                struct notifier_block *n)
{
        unsigned long flags;
        int ret;

        spin_lock_irqsave(&nh->lock, flags);
        ret = notifier_chain_register(&nh->head, n);
        spin_unlock_irqrestore(&nh->lock, flags);
        return ret;
}
EXPORT_SYMBOL_GPL(atomic_notifier_chain_register);
------

  reply	other threads:[~2021-11-12 18:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20211108101157.15189-1-bp@alien8.de>
2021-11-08 10:11 ` [PATCH v0 39/42] crypto: ccree - check notifier registration return value Borislav Petkov
2021-11-12 18:32   ` Cristian Marussi [this message]
2021-11-12 18:48     ` Borislav Petkov
2021-11-08 10:11 ` [PATCH v0 42/42] notifier: Return an error when callback is already registered Borislav Petkov
2021-11-08 14:07   ` Geert Uytterhoeven
2021-11-08 14:21     ` Borislav Petkov
2021-11-08 15:25       ` Geert Uytterhoeven
2021-11-08 15:58         ` Borislav Petkov
2021-11-08 16:12           ` Geert Uytterhoeven
2021-11-08 16:21             ` Borislav Petkov
2021-11-08 20:59               ` Alan Stern
2021-11-08 21:18                 ` Borislav Petkov
2021-11-08 10:19 ` [PATCH v0 00/42] notifiers: " Borislav Petkov
2021-11-08 14:17   ` Alan Stern
2021-11-08 14:24     ` Borislav Petkov
2021-11-08 14:35       ` Borislav Petkov
2021-11-08 16:23         ` Steven Rostedt
2021-11-08 16:29           ` Borislav Petkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211112183233.GB6655@e120937-lin \
    --to=cristian.marussi@arm.com \
    --cc=bp@alien8.de \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).