hwrng: move some code out mutex_lock for avoiding underlying deadlock
authorAmos Kong <akong@redhat.com>
Mon, 8 Dec 2014 08:50:36 +0000 (16:50 +0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 22 Dec 2014 12:02:38 +0000 (23:02 +1100)
In next patch, we use reference counting for each struct hwrng,
changing reference count also needs to take mutex_lock. Before
releasing the lock, if we try to stop a kthread that waits to
take the lock to reduce the referencing count, deadlock will
occur.

Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/char/hw_random/core.c

index 2dd3144d69b1c626652816c01d928f6d928442b1..b4c0e873d36245c07b6b8ecb1f102e7ab2e411b7 100644 (file)
@@ -470,12 +470,12 @@ void hwrng_unregister(struct hwrng *rng)
                }
        }
        if (list_empty(&rng_list)) {
+               mutex_unlock(&rng_mutex);
                unregister_miscdev();
                if (hwrng_fill)
                        kthread_stop(hwrng_fill);
-       }
-
-       mutex_unlock(&rng_mutex);
+       } else
+               mutex_unlock(&rng_mutex);
 }
 EXPORT_SYMBOL_GPL(hwrng_unregister);
 
This page took 0.027567 seconds and 5 git commands to generate.