Skip to content

Commit

Permalink
dlmfs: convert dlmfs_file_read() to copy_to_user()
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Apr 23, 2020
1 parent 3d3185a commit 0702e4f
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions fs/ocfs2/dlmfs/dlmfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static ssize_t dlmfs_file_read(struct file *filp,
loff_t *ppos)
{
int bytes_left;
ssize_t readlen, got;
ssize_t got;
char *lvb_buf;
struct inode *inode = file_inode(filp);

Expand All @@ -237,36 +237,31 @@ static ssize_t dlmfs_file_read(struct file *filp,
if (*ppos >= i_size_read(inode))
return 0;

/* don't read past the lvb */
if (count > i_size_read(inode) - *ppos)
count = i_size_read(inode) - *ppos;

if (!count)
return 0;

if (!access_ok(buf, count))
return -EFAULT;

/* don't read past the lvb */
if ((count + *ppos) > i_size_read(inode))
readlen = i_size_read(inode) - *ppos;
else
readlen = count;

lvb_buf = kmalloc(readlen, GFP_NOFS);
lvb_buf = kmalloc(count, GFP_NOFS);
if (!lvb_buf)
return -ENOMEM;

got = user_dlm_read_lvb(inode, lvb_buf, readlen);
got = user_dlm_read_lvb(inode, lvb_buf, count);
if (got) {
BUG_ON(got != readlen);
bytes_left = __copy_to_user(buf, lvb_buf, readlen);
readlen -= bytes_left;
BUG_ON(got != count);
bytes_left = copy_to_user(buf, lvb_buf, count);
count -= bytes_left;
} else
readlen = 0;
count = 0;

kfree(lvb_buf);

*ppos = *ppos + readlen;
*ppos = *ppos + count;

mlog(0, "read %zd bytes\n", readlen);
return readlen;
mlog(0, "read %zu bytes\n", count);
return count;
}

static ssize_t dlmfs_file_write(struct file *filp,
Expand Down

0 comments on commit 0702e4f

Please sign in to comment.