Commit 0a484a3a authored by Antonino A. Daplas's avatar Antonino A. Daplas Committed by Linus Torvalds

[PATCH] fbdev: Fix return code of fb_read and fb_write

Make fb_read() and fb_write() return 0 (EOF) instead of -ENOSPC if reading at
or past the end of the framebuffer.  This fixes user space apps hanging if
info->fix.smem_len == 0.

Whitespace changes.
Signed-off-by: default avatarAntonino Daplas <adaplas@pol.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 244ab72d
...@@ -589,17 +589,19 @@ fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) ...@@ -589,17 +589,19 @@ fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
return info->fbops->fb_read(file, buf, count, ppos); return info->fbops->fb_read(file, buf, count, ppos);
total_size = info->screen_size; total_size = info->screen_size;
if (total_size == 0) if (total_size == 0)
total_size = info->fix.smem_len; total_size = info->fix.smem_len;
if (p >= total_size) if (p >= total_size)
return 0; return 0;
if (count >= total_size) if (count >= total_size)
count = total_size; count = total_size;
if (count + p > total_size) if (count + p > total_size)
count = total_size - p; count = total_size - p;
cnt = 0;
buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
GFP_KERNEL); GFP_KERNEL);
if (!buffer) if (!buffer)
...@@ -636,6 +638,7 @@ fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) ...@@ -636,6 +638,7 @@ fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
} }
kfree(buffer); kfree(buffer);
return (err) ? err : cnt; return (err) ? err : cnt;
} }
...@@ -648,7 +651,7 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) ...@@ -648,7 +651,7 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
struct fb_info *info = registered_fb[fbidx]; struct fb_info *info = registered_fb[fbidx];
u32 *buffer, *src; u32 *buffer, *src;
u32 __iomem *dst; u32 __iomem *dst;
int c, i, cnt = 0, err; int c, i, cnt = 0, err = 0;
unsigned long total_size; unsigned long total_size;
if (!info || !info->screen_base) if (!info || !info->screen_base)
...@@ -661,19 +664,19 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) ...@@ -661,19 +664,19 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
return info->fbops->fb_write(file, buf, count, ppos); return info->fbops->fb_write(file, buf, count, ppos);
total_size = info->screen_size; total_size = info->screen_size;
if (total_size == 0) if (total_size == 0)
total_size = info->fix.smem_len; total_size = info->fix.smem_len;
if (p > total_size) if (p > total_size)
return -ENOSPC; return 0;
if (count >= total_size) if (count >= total_size)
count = total_size; count = total_size;
err = 0;
if (count + p > total_size) { if (count + p > total_size)
count = total_size - p; count = total_size - p;
err = -ENOSPC;
}
cnt = 0;
buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count,
GFP_KERNEL); GFP_KERNEL);
if (!buffer) if (!buffer)
...@@ -687,12 +690,15 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) ...@@ -687,12 +690,15 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
while (count) { while (count) {
c = (count > PAGE_SIZE) ? PAGE_SIZE : count; c = (count > PAGE_SIZE) ? PAGE_SIZE : count;
src = buffer; src = buffer;
if (copy_from_user(src, buf, c)) { if (copy_from_user(src, buf, c)) {
err = -EFAULT; err = -EFAULT;
break; break;
} }
for (i = c >> 2; i--; ) for (i = c >> 2; i--; )
fb_writel(*src++, dst++); fb_writel(*src++, dst++);
if (c & 3) { if (c & 3) {
u8 *src8 = (u8 *) src; u8 *src8 = (u8 *) src;
u8 __iomem *dst8 = (u8 __iomem *) dst; u8 __iomem *dst8 = (u8 __iomem *) dst;
...@@ -702,11 +708,13 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) ...@@ -702,11 +708,13 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
dst = (u32 __iomem *) dst8; dst = (u32 __iomem *) dst8;
} }
*ppos += c; *ppos += c;
buf += c; buf += c;
cnt += c; cnt += c;
count -= c; count -= c;
} }
kfree(buffer); kfree(buffer);
return (err) ? err : cnt; return (err) ? err : cnt;
......
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