aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/hw_random.h
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2014-12-08 16:50:37 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2014-12-22 23:02:39 +1100
commit3a2c0ba5ad00c018c0bef39a2224aca950aa33f2 (patch)
tree1fbf69fb820c0fa2e6050f8caaecff424c73bd8d /include/linux/hw_random.h
parenthwrng: move some code out mutex_lock for avoiding underlying deadlock (diff)
downloadlinux-dev-3a2c0ba5ad00c018c0bef39a2224aca950aa33f2.tar.xz
linux-dev-3a2c0ba5ad00c018c0bef39a2224aca950aa33f2.zip
hwrng: use reference counts on each struct hwrng.
current_rng holds one reference, and we bump it every time we want to do a read from it. This means we only hold the rng_mutex to grab or drop a reference, so accessing /sys/devices/virtual/misc/hw_random/rng_current doesn't block on read of /dev/hwrng. Using a kref is overkill (we're always under the rng_mutex), but a standard pattern. This also solves the problem that the hwrng_fillfn thread was accessing current_rng without a lock, which could change (eg. to NULL) underneath it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Amos Kong <akong@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include/linux/hw_random.h')
-rw-r--r--include/linux/hw_random.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/include/linux/hw_random.h b/include/linux/hw_random.h
index 914bb08cd738..c212e71ea886 100644
--- a/include/linux/hw_random.h
+++ b/include/linux/hw_random.h
@@ -14,6 +14,7 @@
#include <linux/types.h>
#include <linux/list.h>
+#include <linux/kref.h>
/**
* struct hwrng - Hardware Random Number Generator driver
@@ -44,6 +45,7 @@ struct hwrng {
/* internal. */
struct list_head list;
+ struct kref ref;
};
/** Register a new Hardware Random Number Generator driver. */