Commit 3d88958e authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds

uml: style fixes in the random driver

Give random.c a style workover while I'm changing it.
Signed-off-by: default avatarJeff Dike <jdike@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5d33e4d7
/* Copyright (C) 2005 Jeff Dike <jdike@addtoit.com> */ /* Copyright (C) 2005 - 2008 Jeff Dike <jdike@{linux.intel,addtoit}.com> */
/* Much of this ripped from drivers/char/hw_random.c, see there for other /* Much of this ripped from drivers/char/hw_random.c, see there for other
* copyright. * copyright.
* *
...@@ -35,7 +36,7 @@ static int rng_dev_open (struct inode *inode, struct file *filp) ...@@ -35,7 +36,7 @@ static int rng_dev_open (struct inode *inode, struct file *filp)
/* enforce read-only access to this chrdev */ /* enforce read-only access to this chrdev */
if ((filp->f_mode & FMODE_READ) == 0) if ((filp->f_mode & FMODE_READ) == 0)
return -EINVAL; return -EINVAL;
if (filp->f_mode & FMODE_WRITE) if ((filp->f_mode & FMODE_WRITE) != 0)
return -EINVAL; return -EINVAL;
return 0; return 0;
...@@ -44,31 +45,31 @@ static int rng_dev_open (struct inode *inode, struct file *filp) ...@@ -44,31 +45,31 @@ static int rng_dev_open (struct inode *inode, struct file *filp)
static atomic_t host_sleep_count = ATOMIC_INIT(0); static atomic_t host_sleep_count = ATOMIC_INIT(0);
static ssize_t rng_dev_read (struct file *filp, char __user *buf, size_t size, static ssize_t rng_dev_read (struct file *filp, char __user *buf, size_t size,
loff_t * offp) loff_t *offp)
{ {
u32 data; u32 data;
int n, ret = 0, have_data; int n, ret = 0, have_data;
while(size){ while (size) {
n = os_read_file(random_fd, &data, sizeof(data)); n = os_read_file(random_fd, &data, sizeof(data));
if(n > 0){ if (n > 0) {
have_data = n; have_data = n;
while (have_data && size) { while (have_data && size) {
if (put_user((u8)data, buf++)) { if (put_user((u8) data, buf++)) {
ret = ret ? : -EFAULT; ret = ret ? : -EFAULT;
break; break;
} }
size--; size--;
ret++; ret++;
have_data--; have_data--;
data>>=8; data >>= 8;
} }
} }
else if(n == -EAGAIN){ else if (n == -EAGAIN) {
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
if (filp->f_flags & O_NONBLOCK) if (filp->f_flags & O_NONBLOCK)
return ret ? : -EAGAIN; return ret ? : -EAGAIN;
atomic_inc(&host_sleep_count); atomic_inc(&host_sleep_count);
reactivate_fd(random_fd, RANDOM_IRQ); reactivate_fd(random_fd, RANDOM_IRQ);
...@@ -85,8 +86,10 @@ static ssize_t rng_dev_read (struct file *filp, char __user *buf, size_t size, ...@@ -85,8 +86,10 @@ static ssize_t rng_dev_read (struct file *filp, char __user *buf, size_t size,
ignore_sigio_fd(random_fd); ignore_sigio_fd(random_fd);
deactivate_fd(random_fd, RANDOM_IRQ); deactivate_fd(random_fd, RANDOM_IRQ);
} }
} }
else return n; else
return n;
if (signal_pending (current)) if (signal_pending (current))
return ret ? : -ERESTARTSYS; return ret ? : -ERESTARTSYS;
} }
...@@ -120,33 +123,33 @@ static int __init rng_init (void) ...@@ -120,33 +123,33 @@ static int __init rng_init (void)
{ {
int err; int err;
err = os_open_file("/dev/random", of_read(OPENFLAGS()), 0); err = os_open_file("/dev/random", of_read(OPENFLAGS()), 0);
if(err < 0) if (err < 0)
goto out; goto out;
random_fd = err; random_fd = err;
err = um_request_irq(RANDOM_IRQ, random_fd, IRQ_READ, random_interrupt, err = um_request_irq(RANDOM_IRQ, random_fd, IRQ_READ, random_interrupt,
IRQF_DISABLED | IRQF_SAMPLE_RANDOM, "random", IRQF_DISABLED | IRQF_SAMPLE_RANDOM, "random",
NULL); NULL);
if(err) if (err)
goto err_out_cleanup_hw; goto err_out_cleanup_hw;
sigio_broken(random_fd, 1); sigio_broken(random_fd, 1);
err = misc_register (&rng_miscdev); err = misc_register (&rng_miscdev);
if (err) { if (err) {
printk (KERN_ERR RNG_MODULE_NAME ": misc device register failed\n"); printk (KERN_ERR RNG_MODULE_NAME ": misc device register "
"failed\n");
goto err_out_cleanup_hw; goto err_out_cleanup_hw;
} }
out:
return err;
out: err_out_cleanup_hw:
return err;
err_out_cleanup_hw:
os_close_file(random_fd); os_close_file(random_fd);
random_fd = -1; random_fd = -1;
goto out; goto out;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment