34 #include <linux/device.h>
36 #include <linux/module.h>
37 #include <linux/kernel.h>
39 #include <linux/sched.h>
43 #include <asm/uaccess.h>
46 #define RNG_MODULE_NAME "hw_random"
47 #define PFX RNG_MODULE_NAME ": "
48 #define RNG_MISCDEV_MINOR 183
51 static struct hwrng *current_rng;
54 static int data_avail;
58 static inline int hwrng_init(
struct hwrng *rng)
62 return rng->
init(rng);
65 static inline void hwrng_cleanup(
struct hwrng *rng)
86 return rng->
read(rng, (
void *)buffer, size, wait);
100 size_t size, loff_t *offp)
118 bytes_read = rng_get_data(current_rng, rng_buffer,
121 if (bytes_read < 0) {
125 data_avail = bytes_read;
170 .open = rng_dev_open,
171 .read = rng_dev_read,
179 .fops = &rng_chrdev_ops,
185 const char *buf,
size_t len)
196 if (rng == current_rng) {
200 err = hwrng_init(rng);
203 hwrng_cleanup(current_rng);
220 const char *
name =
"none";
226 name = current_rng->
name;
259 hwrng_attr_current_show,
260 hwrng_attr_current_store);
262 hwrng_attr_available_show,
266 static void unregister_miscdev(
void)
273 static int register_miscdev(
void)
281 &dev_attr_rng_current);
285 &dev_attr_rng_available);
287 goto err_remove_current;
300 int must_register_misc;
317 must_register_misc = (current_rng ==
NULL);
318 old_rng = current_rng;
320 err = hwrng_init(rng);
326 if (must_register_misc) {
327 err = register_miscdev();
336 INIT_LIST_HEAD(&rng->
list);
352 if (current_rng == rng) {
354 if (list_empty(&rng_list)) {
358 err = hwrng_init(current_rng);
363 if (list_empty(&rng_list))
364 unregister_miscdev();