Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 57091
b: refs/heads/master
c: 7f397dc
h: refs/heads/master
i:
  57089: 033d04f
  57087: c4afeac
v: v3
  • Loading branch information
Matt Mackall authored and Linus Torvalds committed May 30, 2007
1 parent f77f040 commit a948d3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 602b6aeefe8932dd8bb15014e8fe6bb25d736361
refs/heads/master: 7f397dcdb78d699a20d96bfcfb595a2411a5bbd2
55 changes: 31 additions & 24 deletions trunk/drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,37 +1020,44 @@ random_poll(struct file *file, poll_table * wait)
return mask;
}

static ssize_t
random_write(struct file * file, const char __user * buffer,
size_t count, loff_t *ppos)
static int
write_pool(struct entropy_store *r, const char __user *buffer, size_t count)
{
int ret = 0;
size_t bytes;
__u32 buf[16];
const char __user *p = buffer;
size_t c = count;

while (c > 0) {
bytes = min(c, sizeof(buf));
while (count > 0) {
bytes = min(count, sizeof(buf));
if (copy_from_user(&buf, p, bytes))
return -EFAULT;

bytes -= copy_from_user(&buf, p, bytes);
if (!bytes) {
ret = -EFAULT;
break;
}
c -= bytes;
count -= bytes;
p += bytes;

add_entropy_words(&input_pool, buf, (bytes + 3) / 4);
}
if (p == buffer) {
return (ssize_t)ret;
} else {
struct inode *inode = file->f_path.dentry->d_inode;
inode->i_mtime = current_fs_time(inode->i_sb);
mark_inode_dirty(inode);
return (ssize_t)(p - buffer);
add_entropy_words(r, buf, (bytes + 3) / 4);
}

return 0;
}

static ssize_t
random_write(struct file * file, const char __user * buffer,
size_t count, loff_t *ppos)
{
size_t ret;
struct inode *inode = file->f_path.dentry->d_inode;

ret = write_pool(&blocking_pool, buffer, count);
if (ret)
return ret;
ret = write_pool(&nonblocking_pool, buffer, count);
if (ret)
return ret;

inode->i_mtime = current_fs_time(inode->i_sb);
mark_inode_dirty(inode);
return (ssize_t)count;
}

static int
Expand Down Expand Up @@ -1089,8 +1096,8 @@ random_ioctl(struct inode * inode, struct file * file,
return -EINVAL;
if (get_user(size, p++))
return -EFAULT;
retval = random_write(file, (const char __user *) p,
size, &file->f_pos);
retval = write_pool(&input_pool, (const char __user *)p,
size);
if (retval < 0)
return retval;
credit_entropy_store(&input_pool, ent_count);
Expand Down

0 comments on commit a948d3b

Please sign in to comment.