Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-2.6-block.git] / drivers / char / hw_random / core.c
index b9495a8c05c6d7e9b192c8a2b403b7fb2ac90fdc..334601cc81cf57ce92e83664ec192a01a5e353c4 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/miscdevice.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/random.h>
 #include <asm/uaccess.h>
 
 
@@ -301,9 +302,10 @@ err_misc_dereg:
 
 int hwrng_register(struct hwrng *rng)
 {
-       int must_register_misc;
        int err = -EINVAL;
        struct hwrng *old_rng, *tmp;
+       unsigned char bytes[16];
+       int bytes_read;
 
        if (rng->name == NULL ||
            (rng->data_read == NULL && rng->read == NULL))
@@ -326,7 +328,6 @@ int hwrng_register(struct hwrng *rng)
                        goto out_unlock;
        }
 
-       must_register_misc = (current_rng == NULL);
        old_rng = current_rng;
        if (!old_rng) {
                err = hwrng_init(rng);
@@ -335,18 +336,20 @@ int hwrng_register(struct hwrng *rng)
                current_rng = rng;
        }
        err = 0;
-       if (must_register_misc) {
+       if (!old_rng) {
                err = register_miscdev();
                if (err) {
-                       if (!old_rng) {
-                               hwrng_cleanup(rng);
-                               current_rng = NULL;
-                       }
+                       hwrng_cleanup(rng);
+                       current_rng = NULL;
                        goto out_unlock;
                }
        }
        INIT_LIST_HEAD(&rng->list);
        list_add_tail(&rng->list, &rng_list);
+
+       bytes_read = rng_get_data(rng, bytes, sizeof(bytes), 1);
+       if (bytes_read > 0)
+               add_device_randomness(bytes, bytes_read);
 out_unlock:
        mutex_unlock(&rng_mutex);
 out: