Commit db77ec270d00098ff4fbf15f62f4506f6efb25d2

Authored by Alan Curry
Committed by Linus Torvalds
1 parent 59153f7d7e

[PATCH] framebuffer: cmap-setting return values

A set of 3 small bugfixes, all of which are related to bogus return values
of fb colormap-setting functions.

First, fb_alloc_cmap returns -1 if memory allocation fails. This is a hard
condition to reproduce since you'd have to be really low on memory, but from
studying the contexts in which it is called, I think this function should be
returning a negative errno, and the -1 will be seen as an EPERM. Switching it
to -ENOMEM makes sense.

Second, the store_cmap function which is called for writes to
/sys/class/graphics/fb0/color_map returns 0 for success, but it should be
returning the count of bytes written since its return value ends up in
userspace as the result of the write() syscall.

Third, radeonfb returns 1 instead of a negative errno when FBIOPUTCMAP is
called with an oversized colormap.  This is seen in userspace as a return
value of 1 from the ioctl() syscall with errno left unchanged.  A more
useful return value would be -EINVAL.

Signed-off-by: Alan Curry <pacman@TheWorld.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

Showing 3 changed files with 7 additions and 7 deletions Side-by-side Diff

drivers/video/aty/radeon_base.c
... ... @@ -1067,7 +1067,7 @@
1067 1067  
1068 1068  
1069 1069 if (regno > 255)
1070   - return 1;
  1070 + return -EINVAL;
1071 1071  
1072 1072 red >>= 8;
1073 1073 green >>= 8;
1074 1074  
... ... @@ -1086,9 +1086,9 @@
1086 1086 pindex = regno * 8;
1087 1087  
1088 1088 if (rinfo->depth == 16 && regno > 63)
1089   - return 1;
  1089 + return -EINVAL;
1090 1090 if (rinfo->depth == 15 && regno > 31)
1091   - return 1;
  1091 + return -EINVAL;
1092 1092  
1093 1093 /* For 565, the green component is mixed one order
1094 1094 * below
drivers/video/fbcmap.c
... ... @@ -85,7 +85,7 @@
85 85 * Allocates memory for a colormap @cmap. @len is the
86 86 * number of entries in the palette.
87 87 *
88   - * Returns -1 errno on error, or zero on success.
  88 + * Returns negative errno on error, or zero on success.
89 89 *
90 90 */
91 91  
... ... @@ -116,7 +116,7 @@
116 116  
117 117 fail:
118 118 fb_dealloc_cmap(cmap);
119   - return -1;
  119 + return -ENOMEM;
120 120 }
121 121  
122 122 /**
drivers/video/fbsysfs.c
... ... @@ -348,7 +348,7 @@
348 348 fb_copy_cmap(&umap, &fb_info->cmap);
349 349 fb_dealloc_cmap(&umap);
350 350  
351   - return rc;
  351 + return rc ?: count;
352 352 }
353 353 for (i = 0; i < length; i++) {
354 354 u16 red, blue, green, tsp;
... ... @@ -367,7 +367,7 @@
367 367 if (transp)
368 368 fb_info->cmap.transp[i] = tsp;
369 369 }
370   - return 0;
  370 + return count;
371 371 }
372 372  
373 373 static ssize_t show_cmap(struct class_device *class_device, char *buf)