Commit 06f42774 authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Sam Ravnborg

fbdev: simplify fb_getput_cmap()

This function is one of the remaining users of compat_alloc_user_space()
and copy_in_user().

Clean it up by copying to a local data structure copy instead,
which also leads to more readable code.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Acked-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200918100926.1447563-1-arnd@arndb.de
parent 8bde6c0d
...@@ -1215,36 +1215,30 @@ struct fb_cmap32 { ...@@ -1215,36 +1215,30 @@ struct fb_cmap32 {
static int fb_getput_cmap(struct fb_info *info, unsigned int cmd, static int fb_getput_cmap(struct fb_info *info, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
struct fb_cmap_user __user *cmap; struct fb_cmap32 cmap32;
struct fb_cmap32 __user *cmap32; struct fb_cmap cmap_from;
__u32 data; struct fb_cmap_user cmap;
int err;
cmap = compat_alloc_user_space(sizeof(*cmap));
cmap32 = compat_ptr(arg);
if (copy_in_user(&cmap->start, &cmap32->start, 2 * sizeof(__u32))) if (copy_from_user(&cmap32, compat_ptr(arg), sizeof(cmap32)))
return -EFAULT; return -EFAULT;
if (get_user(data, &cmap32->red) || cmap = (struct fb_cmap_user) {
put_user(compat_ptr(data), &cmap->red) || .start = cmap32.start,
get_user(data, &cmap32->green) || .len = cmap32.len,
put_user(compat_ptr(data), &cmap->green) || .red = compat_ptr(cmap32.red),
get_user(data, &cmap32->blue) || .green = compat_ptr(cmap32.green),
put_user(compat_ptr(data), &cmap->blue) || .blue = compat_ptr(cmap32.blue),
get_user(data, &cmap32->transp) || .transp = compat_ptr(cmap32.transp),
put_user(compat_ptr(data), &cmap->transp)) };
return -EFAULT;
err = do_fb_ioctl(info, cmd, (unsigned long) cmap); if (cmd == FBIOPUTCMAP)
return fb_set_user_cmap(&cmap, info);
if (!err) { lock_fb_info(info);
if (copy_in_user(&cmap32->start, cmap_from = info->cmap;
&cmap->start, unlock_fb_info(info);
2 * sizeof(__u32)))
err = -EFAULT; return fb_cmap_to_user(&cmap_from, &cmap);
}
return err;
} }
static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix, static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
......
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