aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds2013-03-05 20:54:28 -0600
committerLinus Torvalds2013-03-05 20:54:28 -0600
commitd7b815d4daac154a029faf4e8b687a75530d43be (patch)
tree3e9f5f974c2cb5b9911382ee544a44652d7e8ee7
parent9da060d0ed571bbff434c4a1ef3e48db99a37ee0 (diff)
parentf7f154f1246ccc5a0a7e9ce50932627d60a0c878 (diff)
downloadam43-linux-kernel-d7b815d4daac154a029faf4e8b687a75530d43be.tar.gz
am43-linux-kernel-d7b815d4daac154a029faf4e8b687a75530d43be.tar.xz
am43-linux-kernel-d7b815d4daac154a029faf4e8b687a75530d43be.zip
Merge tag 'fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux
Pull virtio hwrng fix from Rusty Russell: "Nasty side-effect of vmalloc'ing modules: their static vars cannot be put into scatterlists. Jens has a check queued for this, so it shouldn't happen again. We could fix this in virtio_rng, but it's actually far easier to just do it in the core" * tag 'fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux: hw_random: make buffer usable in scatterlist.
-rw-r--r--drivers/char/hw_random/core.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index 1bafb40ec8a..69ae5972713 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -40,6 +40,7 @@
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/miscdevice.h> 41#include <linux/miscdevice.h>
42#include <linux/delay.h> 42#include <linux/delay.h>
43#include <linux/slab.h>
43#include <asm/uaccess.h> 44#include <asm/uaccess.h>
44 45
45 46
@@ -52,8 +53,12 @@ static struct hwrng *current_rng;
52static LIST_HEAD(rng_list); 53static LIST_HEAD(rng_list);
53static DEFINE_MUTEX(rng_mutex); 54static DEFINE_MUTEX(rng_mutex);
54static int data_avail; 55static int data_avail;
55static u8 rng_buffer[SMP_CACHE_BYTES < 32 ? 32 : SMP_CACHE_BYTES] 56static u8 *rng_buffer;
56 __cacheline_aligned; 57
58static size_t rng_buffer_size(void)
59{
60 return SMP_CACHE_BYTES < 32 ? 32 : SMP_CACHE_BYTES;
61}
57 62
58static inline int hwrng_init(struct hwrng *rng) 63static inline int hwrng_init(struct hwrng *rng)
59{ 64{
@@ -116,7 +121,7 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,
116 121
117 if (!data_avail) { 122 if (!data_avail) {
118 bytes_read = rng_get_data(current_rng, rng_buffer, 123 bytes_read = rng_get_data(current_rng, rng_buffer,
119 sizeof(rng_buffer), 124 rng_buffer_size(),
120 !(filp->f_flags & O_NONBLOCK)); 125 !(filp->f_flags & O_NONBLOCK));
121 if (bytes_read < 0) { 126 if (bytes_read < 0) {
122 err = bytes_read; 127 err = bytes_read;
@@ -307,6 +312,14 @@ int hwrng_register(struct hwrng *rng)
307 312
308 mutex_lock(&rng_mutex); 313 mutex_lock(&rng_mutex);
309 314
315 /* kmalloc makes this safe for virt_to_page() in virtio_rng.c */
316 err = -ENOMEM;
317 if (!rng_buffer) {
318 rng_buffer = kmalloc(rng_buffer_size(), GFP_KERNEL);
319 if (!rng_buffer)
320 goto out_unlock;
321 }
322
310 /* Must not register two RNGs with the same name. */ 323 /* Must not register two RNGs with the same name. */
311 err = -EEXIST; 324 err = -EEXIST;
312 list_for_each_entry(tmp, &rng_list, list) { 325 list_for_each_entry(tmp, &rng_list, list) {