Commit f1a43f93 authored by Akinobu Mita's avatar Akinobu Mita Committed by Linus Torvalds

ipc: use simple_read_from_buffer()

Also this patch kills unneccesary trailing NULL character.
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Cc: Nadia Derbey <Nadia.Derbey@bull.net>
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: Pierre Peiffer <peifferp@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 380af1b3
...@@ -314,15 +314,11 @@ static int mqueue_unlink(struct inode *dir, struct dentry *dentry) ...@@ -314,15 +314,11 @@ static int mqueue_unlink(struct inode *dir, struct dentry *dentry)
* through std routines) * through std routines)
*/ */
static ssize_t mqueue_read_file(struct file *filp, char __user *u_data, static ssize_t mqueue_read_file(struct file *filp, char __user *u_data,
size_t count, loff_t * off) size_t count, loff_t *off)
{ {
struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode); struct mqueue_inode_info *info = MQUEUE_I(filp->f_path.dentry->d_inode);
char buffer[FILENT_SIZE]; char buffer[FILENT_SIZE];
size_t slen; ssize_t ret;
loff_t o;
if (!count)
return 0;
spin_lock(&info->lock); spin_lock(&info->lock);
snprintf(buffer, sizeof(buffer), snprintf(buffer, sizeof(buffer),
...@@ -335,21 +331,14 @@ static ssize_t mqueue_read_file(struct file *filp, char __user *u_data, ...@@ -335,21 +331,14 @@ static ssize_t mqueue_read_file(struct file *filp, char __user *u_data,
pid_vnr(info->notify_owner)); pid_vnr(info->notify_owner));
spin_unlock(&info->lock); spin_unlock(&info->lock);
buffer[sizeof(buffer)-1] = '\0'; buffer[sizeof(buffer)-1] = '\0';
slen = strlen(buffer)+1;
o = *off;
if (o > slen)
return 0;
if (o + count > slen) ret = simple_read_from_buffer(u_data, count, off, buffer,
count = slen - o; strlen(buffer));
if (ret <= 0)
if (copy_to_user(u_data, buffer + o, count)) return ret;
return -EFAULT;
*off = o + count;
filp->f_path.dentry->d_inode->i_atime = filp->f_path.dentry->d_inode->i_ctime = CURRENT_TIME; filp->f_path.dentry->d_inode->i_atime = filp->f_path.dentry->d_inode->i_ctime = CURRENT_TIME;
return count; return ret;
} }
static int mqueue_flush_file(struct file *filp, fl_owner_t id) static int mqueue_flush_file(struct file *filp, fl_owner_t id)
......
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