Skip to content

Commit

Permalink
[PATCH] fbdev: Fix return error of fb_write
Browse files Browse the repository at this point in the history
Fix return code of fb_write():

If at least 1 byte was transferred to the device, return number of bytes,
otherwise:

    - return -EFBIG - if file offset is past the maximum allowable offset or
      size is greater than framebuffer length
    - return -ENOSPC - if size is greater than framebuffer length - offset

Signed-off-by: Antonino Daplas <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
adaplas authored and Linus Torvalds committed Apr 19, 2006
1 parent a61bdaa commit 6a2a886
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions drivers/video/fbmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,19 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
total_size = info->fix.smem_len;

if (p > total_size)
return 0;
return -EFBIG;

if (count >= total_size)
if (count > total_size) {
err = -EFBIG;
count = total_size;
}

if (count + p > total_size) {
if (!err)
err = -ENOSPC;

if (count + p > total_size)
count = total_size - p;
}

buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
GFP_KERNEL);
Expand Down Expand Up @@ -722,7 +728,7 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)

kfree(buffer);

return (err) ? err : cnt;
return (cnt) ? cnt : err;
}

#ifdef CONFIG_KMOD
Expand Down

0 comments on commit 6a2a886

Please sign in to comment.