diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2014-01-30 06:49:43 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2014-02-08 20:59:27 -0500 |
commit | d167b6e1fb8ad386b17485ca88804d14f1695805 (patch) | |
tree | 17edae29c16bc089530bf54512ca5f51de88d399 /drivers/char/hw_random/core.c | |
parent | fecfd7f7e91fc1e82d44b0e64a6bda8133f2037b (diff) |
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: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/char/hw_random/core.c')
-rw-r--r-- | drivers/char/hw_random/core.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c index a0f7724852eb..cf49f1c88f01 100644 --- a/drivers/char/hw_random/core.c +++ b/drivers/char/hw_random/core.c | |||
@@ -302,7 +302,6 @@ err_misc_dereg: | |||
302 | 302 | ||
303 | int hwrng_register(struct hwrng *rng) | 303 | int hwrng_register(struct hwrng *rng) |
304 | { | 304 | { |
305 | int must_register_misc; | ||
306 | int err = -EINVAL; | 305 | int err = -EINVAL; |
307 | struct hwrng *old_rng, *tmp; | 306 | struct hwrng *old_rng, *tmp; |
308 | 307 | ||
@@ -327,7 +326,6 @@ int hwrng_register(struct hwrng *rng) | |||
327 | goto out_unlock; | 326 | goto out_unlock; |
328 | } | 327 | } |
329 | 328 | ||
330 | must_register_misc = (current_rng == NULL); | ||
331 | old_rng = current_rng; | 329 | old_rng = current_rng; |
332 | if (!old_rng) { | 330 | if (!old_rng) { |
333 | err = hwrng_init(rng); | 331 | err = hwrng_init(rng); |
@@ -336,13 +334,11 @@ int hwrng_register(struct hwrng *rng) | |||
336 | current_rng = rng; | 334 | current_rng = rng; |
337 | } | 335 | } |
338 | err = 0; | 336 | err = 0; |
339 | if (must_register_misc) { | 337 | if (!old_rng) { |
340 | err = register_miscdev(); | 338 | err = register_miscdev(); |
341 | if (err) { | 339 | if (err) { |
342 | if (!old_rng) { | 340 | hwrng_cleanup(rng); |
343 | hwrng_cleanup(rng); | 341 | current_rng = NULL; |
344 | current_rng = NULL; | ||
345 | } | ||
346 | goto out_unlock; | 342 | goto out_unlock; |
347 | } | 343 | } |
348 | } | 344 | } |