From: Rusty Russell <rusty@rustcorp.com.au>
To: Dan Carpenter <dan.carpenter@oracle.com>, Matt Mackall <mpm@selenic.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
Satoru Takeuchi <satoru.takeuchi@gmail.com>,
Paul Gortmaker <paul.gortmaker@windriver.com>,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] hw_random: cleanup in hwrng_register()
Date: Fri, 31 Jan 2014 16:18:51 +1030 [thread overview]
Message-ID: <87k3dgvgzg.fsf@rustcorp.com.au> (raw)
In-Reply-To: <20140130114943.GB12734@elgon.mountain>
Dan Carpenter <dan.carpenter@oracle.com> writes:
> My static checker complains that:
>
> drivers/char/hw_random/core.c:341 hwrng_register()
> warn: we tested 'old_rng' before and it was 'false'
>
> The problem is that sometimes we test "if (!old_rng)" and sometimes we
> test "if (must_register_misc)". The static checker knows they are
> equivalent but a human being reading the code could easily be confused.
>
> I have simplified the code by removing the "must_register_misc" variable
> and I have removed the redundant check on "if (!old_rng)".
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Yeah, clearer too.
Reviewed-by: Rusty Russell <rusty@rustcorp.com.au>
Thanks,
Rusty.
>
> diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
> index b9495a8c05c6..463382036a01 100644
> --- a/drivers/char/hw_random/core.c
> +++ b/drivers/char/hw_random/core.c
> @@ -301,7 +301,6 @@ err_misc_dereg:
>
> int hwrng_register(struct hwrng *rng)
> {
> - int must_register_misc;
> int err = -EINVAL;
> struct hwrng *old_rng, *tmp;
>
> @@ -326,7 +325,6 @@ int hwrng_register(struct hwrng *rng)
> goto out_unlock;
> }
>
> - must_register_misc = (current_rng == NULL);
> old_rng = current_rng;
> if (!old_rng) {
> err = hwrng_init(rng);
> @@ -335,13 +333,11 @@ int hwrng_register(struct hwrng *rng)
> current_rng = rng;
> }
> err = 0;
> - if (must_register_misc) {
> + if (!old_rng) {
> err = register_miscdev();
> if (err) {
> - if (!old_rng) {
> - hwrng_cleanup(rng);
> - current_rng = NULL;
> - }
> + hwrng_cleanup(rng);
> + current_rng = NULL;
> goto out_unlock;
> }
> }
next prev parent reply other threads:[~2014-02-01 8:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-30 11:49 Dan Carpenter
2014-01-31 5:48 ` Rusty Russell [this message]
2014-02-09 9:22 ` Herbert Xu
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=87k3dgvgzg.fsf@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=dan.carpenter@oracle.com \
--cc=herbert@gondor.apana.org.au \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpm@selenic.com \
--cc=paul.gortmaker@windriver.com \
--cc=satoru.takeuchi@gmail.com \
/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
Powered by JetHome