hwrng: cleanup in hwrng_register()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 30 Jan 2014 11:49:43 +0000 (14:49 +0300)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sun, 9 Feb 2014 01:59:27 +0000 (09:59 +0800)
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>
Reviewed-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/char/hw_random/core.c

index a0f7724..cf49f1c 100644 (file)
@@ -302,7 +302,6 @@ err_misc_dereg:
 
 int hwrng_register(struct hwrng *rng)
 {
-       int must_register_misc;
        int err = -EINVAL;
        struct hwrng *old_rng, *tmp;
 
@@ -327,7 +326,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);
@@ -336,13 +334,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;
                }
        }