Merge git://git.infradead.org/~dedekind/ubi-2.6
[pandora-kernel.git] / drivers / char / hw_random / core.c
index 26a860a..662d60e 100644 (file)
@@ -66,11 +66,11 @@ static inline void hwrng_cleanup(struct hwrng *rng)
                rng->cleanup(rng);
 }
 
-static inline int hwrng_data_present(struct hwrng *rng)
+static inline int hwrng_data_present(struct hwrng *rng, int wait)
 {
        if (!rng->data_present)
                return 1;
-       return rng->data_present(rng);
+       return rng->data_present(rng, wait);
 }
 
 static inline int hwrng_data_read(struct hwrng *rng, u32 *data)
@@ -94,8 +94,7 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,
 {
        u32 data;
        ssize_t ret = 0;
-       int i, err = 0;
-       int data_present;
+       int err = 0;
        int bytes_read;
 
        while (size) {
@@ -107,27 +106,20 @@ static ssize_t rng_dev_read(struct file *filp, char __user *buf,
                        err = -ENODEV;
                        goto out;
                }
-               if (filp->f_flags & O_NONBLOCK) {
-                       data_present = hwrng_data_present(current_rng);
-               } else {
-                       /* Some RNG require some time between data_reads to gather
-                        * new entropy. Poll it.
-                        */
-                       for (i = 0; i < 20; i++) {
-                               data_present = hwrng_data_present(current_rng);
-                               if (data_present)
-                                       break;
-                               udelay(10);
-                       }
-               }
+
                bytes_read = 0;
-               if (data_present)
+               if (hwrng_data_present(current_rng,
+                                      !(filp->f_flags & O_NONBLOCK)))
                        bytes_read = hwrng_data_read(current_rng, &data);
                mutex_unlock(&rng_mutex);
 
                err = -EAGAIN;
                if (!bytes_read && (filp->f_flags & O_NONBLOCK))
                        goto out;
+               if (bytes_read < 0) {
+                       err = bytes_read;
+                       goto out;
+               }
 
                err = -EFAULT;
                while (bytes_read && size) {