Skip to content

Commit

Permalink
[PATCH] kmsg_write: don't return printk return value
Browse files Browse the repository at this point in the history
kmsg_write returns with printk, so some programs may be confused by a
successful write() with a return value different than the buffer length.

# /bin/echo something > /dev/kmsg
/bin/echo: write error: Inappropriate ioctl for device

The drawbacks is that the printk return value can no more be quickly
checked from userspace.

Signed-off-by: Guillaume Chazarain <guichaz@yahoo.fr>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Guillaume Chazarain authored and Linus Torvalds committed Jan 9, 2006
1 parent 025510c commit cd140a5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/char/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ static ssize_t kmsg_write(struct file * file, const char __user * buf,
size_t count, loff_t *ppos)
{
char *tmp;
int ret;
ssize_t ret;

tmp = kmalloc(count + 1, GFP_KERNEL);
if (tmp == NULL)
Expand All @@ -826,6 +826,9 @@ static ssize_t kmsg_write(struct file * file, const char __user * buf,
if (!copy_from_user(tmp, buf, count)) {
tmp[count] = 0;
ret = printk("%s", tmp);
if (ret > count)
/* printk can add a prefix */
ret = count;
}
kfree(tmp);
return ret;
Expand Down

0 comments on commit cd140a5

Please sign in to comment.