diff options
author | Arnd Bergmann <arnd@arndb.de> | 2020-09-18 12:09:04 +0200 |
---|---|---|
committer | Sam Ravnborg <sam@ravnborg.org> | 2020-09-25 16:34:50 +0200 |
commit | 06f4277463ba695287829e0b52d9b82be44f99bf (patch) | |
tree | ed7a746a922fd5656478d12d210ea7e74f6c69df /drivers/video/fbdev/core/fbmem.c | |
parent | 8bde6c0d4e7374fedeca959af42ad6819c792e08 (diff) | |
download | linux-stable-06f4277463ba695287829e0b52d9b82be44f99bf.tar.gz linux-stable-06f4277463ba695287829e0b52d9b82be44f99bf.tar.bz2 linux-stable-06f4277463ba695287829e0b52d9b82be44f99bf.zip |
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: Arnd Bergmann <arnd@arndb.de>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200918100926.1447563-1-arnd@arndb.de
Diffstat (limited to 'drivers/video/fbdev/core/fbmem.c')
-rw-r--r-- | drivers/video/fbdev/core/fbmem.c | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index 8268bbee8cae..9e5c78e00995 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1215,36 +1215,30 @@ struct fb_cmap32 { static int fb_getput_cmap(struct fb_info *info, unsigned int cmd, unsigned long arg) { - struct fb_cmap_user __user *cmap; - struct fb_cmap32 __user *cmap32; - __u32 data; - int err; - - cmap = compat_alloc_user_space(sizeof(*cmap)); - cmap32 = compat_ptr(arg); + struct fb_cmap32 cmap32; + struct fb_cmap cmap_from; + struct fb_cmap_user cmap; - if (copy_in_user(&cmap->start, &cmap32->start, 2 * sizeof(__u32))) + if (copy_from_user(&cmap32, compat_ptr(arg), sizeof(cmap32))) return -EFAULT; - if (get_user(data, &cmap32->red) || - put_user(compat_ptr(data), &cmap->red) || - get_user(data, &cmap32->green) || - put_user(compat_ptr(data), &cmap->green) || - get_user(data, &cmap32->blue) || - put_user(compat_ptr(data), &cmap->blue) || - get_user(data, &cmap32->transp) || - put_user(compat_ptr(data), &cmap->transp)) - return -EFAULT; + cmap = (struct fb_cmap_user) { + .start = cmap32.start, + .len = cmap32.len, + .red = compat_ptr(cmap32.red), + .green = compat_ptr(cmap32.green), + .blue = compat_ptr(cmap32.blue), + .transp = compat_ptr(cmap32.transp), + }; - err = do_fb_ioctl(info, cmd, (unsigned long) cmap); + if (cmd == FBIOPUTCMAP) + return fb_set_user_cmap(&cmap, info); - if (!err) { - if (copy_in_user(&cmap32->start, - &cmap->start, - 2 * sizeof(__u32))) - err = -EFAULT; - } - return err; + lock_fb_info(info); + cmap_from = info->cmap; + unlock_fb_info(info); + + return fb_cmap_to_user(&cmap_from, &cmap); } static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix, |