Commit d167b6e1 authored by Dan Carpenter's avatar Dan Carpenter Committed by Herbert Xu

hwrng: cleanup in hwrng_register()

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: default avatarDan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent fecfd7f7
...@@ -302,7 +302,6 @@ static int register_miscdev(void) ...@@ -302,7 +302,6 @@ static int register_miscdev(void)
int hwrng_register(struct hwrng *rng) int hwrng_register(struct hwrng *rng)
{ {
int must_register_misc;
int err = -EINVAL; int err = -EINVAL;
struct hwrng *old_rng, *tmp; struct hwrng *old_rng, *tmp;
...@@ -327,7 +326,6 @@ int hwrng_register(struct hwrng *rng) ...@@ -327,7 +326,6 @@ int hwrng_register(struct hwrng *rng)
goto out_unlock; goto out_unlock;
} }
must_register_misc = (current_rng == NULL);
old_rng = current_rng; old_rng = current_rng;
if (!old_rng) { if (!old_rng) {
err = hwrng_init(rng); err = hwrng_init(rng);
...@@ -336,13 +334,11 @@ int hwrng_register(struct hwrng *rng) ...@@ -336,13 +334,11 @@ int hwrng_register(struct hwrng *rng)
current_rng = rng; current_rng = rng;
} }
err = 0; err = 0;
if (must_register_misc) { if (!old_rng) {
err = register_miscdev(); err = register_miscdev();
if (err) { if (err) {
if (!old_rng) { hwrng_cleanup(rng);
hwrng_cleanup(rng); current_rng = NULL;
current_rng = NULL;
}
goto out_unlock; goto out_unlock;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment