Commit 03e259a9 authored by Michal Januszewski's avatar Michal Januszewski Committed by Linus Torvalds

[PATCH] fbdev: update info->cmap when setting cmap from user-/kernelspace.

The fb_info struct, as defined in include/linux/fb.h, contains an element
that is supposed to hold the current color map:
  struct fb_cmap cmap;            /* Current cmap */

This cmap is currently never updated when either fb_set_cmap() or
fb_set_user_cmap() are called.  As a result, info->cmap contains the
default cmap that was set by a device driver/fbcon and a userspace
application using the FBIOGETCMAP ioctl will not always get the *currently*
used color map.

The patch fixes this by making sure the cmap is copied to info->cmap after
it is set correctly.  It moves most of the code that is responsible for
setting the cmap to fb_set_cmap() and out of fb_set_user_cmap() to avoid
code-duplication.
Signed-off-by: default avatarMichal Januszewski <spock@gentoo.org>
Cc: <linux-fbdev-devel@lists.sourceforge.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent dbd4f128
...@@ -212,7 +212,7 @@ int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to) ...@@ -212,7 +212,7 @@ int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to)
int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info) int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info)
{ {
int i, start; int i, start, rc = 0;
u16 *red, *green, *blue, *transp; u16 *red, *green, *blue, *transp;
u_int hred, hgreen, hblue, htransp = 0xffff; u_int hred, hgreen, hblue, htransp = 0xffff;
...@@ -225,8 +225,9 @@ int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info) ...@@ -225,8 +225,9 @@ int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info)
if (start < 0 || (!info->fbops->fb_setcolreg && if (start < 0 || (!info->fbops->fb_setcolreg &&
!info->fbops->fb_setcmap)) !info->fbops->fb_setcmap))
return -EINVAL; return -EINVAL;
if (info->fbops->fb_setcmap) if (info->fbops->fb_setcmap) {
return info->fbops->fb_setcmap(cmap, info); rc = info->fbops->fb_setcmap(cmap, info);
} else {
for (i = 0; i < cmap->len; i++) { for (i = 0; i < cmap->len; i++) {
hred = *red++; hred = *red++;
hgreen = *green++; hgreen = *green++;
...@@ -234,66 +235,41 @@ int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info) ...@@ -234,66 +235,41 @@ int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *info)
if (transp) if (transp)
htransp = *transp++; htransp = *transp++;
if (info->fbops->fb_setcolreg(start++, if (info->fbops->fb_setcolreg(start++,
hred, hgreen, hblue, htransp, hred, hgreen, hblue,
info)) htransp, info))
break; break;
} }
return 0; }
if (rc == 0)
fb_copy_cmap(cmap, &info->cmap);
return rc;
} }
int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info) int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
{ {
int i, start; int rc, size = cmap->len * sizeof(u16);
u16 __user *red, *green, *blue, *transp; struct fb_cmap umap;
u_int hred, hgreen, hblue, htransp = 0xffff;
red = cmap->red;
green = cmap->green;
blue = cmap->blue;
transp = cmap->transp;
start = cmap->start;
if (start < 0 || (!info->fbops->fb_setcolreg && if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
!info->fbops->fb_setcmap)) !info->fbops->fb_setcmap))
return -EINVAL; return -EINVAL;
/* If we can batch, do it */
if (info->fbops->fb_setcmap && cmap->len > 1) {
struct fb_cmap umap;
int size = cmap->len * sizeof(u16);
int rc;
memset(&umap, 0, sizeof(struct fb_cmap)); memset(&umap, 0, sizeof(struct fb_cmap));
rc = fb_alloc_cmap(&umap, cmap->len, transp != NULL); rc = fb_alloc_cmap(&umap, cmap->len, cmap->transp != NULL);
if (rc) if (rc)
return rc; return rc;
if (copy_from_user(umap.red, red, size) || if (copy_from_user(umap.red, cmap->red, size) ||
copy_from_user(umap.green, green, size) || copy_from_user(umap.green, cmap->green, size) ||
copy_from_user(umap.blue, blue, size) || copy_from_user(umap.blue, cmap->blue, size) ||
(transp && copy_from_user(umap.transp, transp, size))) { (cmap->transp && copy_from_user(umap.transp, cmap->transp, size))) {
rc = -EFAULT;
}
umap.start = start;
if (rc == 0)
rc = info->fbops->fb_setcmap(&umap, info);
fb_dealloc_cmap(&umap); fb_dealloc_cmap(&umap);
return rc;
}
for (i = 0; i < cmap->len; i++, red++, blue++, green++) {
if (get_user(hred, red) ||
get_user(hgreen, green) ||
get_user(hblue, blue) ||
(transp && get_user(htransp, transp)))
return -EFAULT; return -EFAULT;
if (info->fbops->fb_setcolreg(start++,
hred, hgreen, hblue, htransp,
info))
return 0;
if (transp)
transp++;
} }
return 0; umap.start = cmap->start;
rc = fb_set_cmap(&umap, info);
fb_dealloc_cmap(&umap);
return rc;
} }
/** /**
......
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