From: Christoph Hellwig <hch@lst.de>
To: Geert Uytterhoeven <geert@linux-m68k.org>,
"David S. Miller" <davem@davemloft.net>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
linux-m68k@lists.linux-m68k.org, sparclinux@vger.kernel.org,
linux-fbdev@vger.kernel.org
Subject: [PATCH 2/3] fbdev/sbuslib: refactor sbusfb_ioctl_helper
Date: Wed, 07 Oct 2020 07:44:46 +0000 [thread overview]
Message-ID: <20201007074447.797968-3-hch@lst.de> (raw)
In-Reply-To: <20201007074447.797968-1-hch@lst.de>
Refactor sbusfb_ioctl_helper into a bunch of self-contained helpers,
to prepare for improvements to the compat ioctl handler.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/video/fbdev/sbuslib.c | 157 ++++++++++++++++------------------
1 file changed, 75 insertions(+), 82 deletions(-)
diff --git a/drivers/video/fbdev/sbuslib.c b/drivers/video/fbdev/sbuslib.c
index 176dbfb5d3efca..1c3bf1cb8dccd7 100644
--- a/drivers/video/fbdev/sbuslib.c
+++ b/drivers/video/fbdev/sbuslib.c
@@ -97,94 +97,87 @@ int sbusfb_mmap_helper(struct sbus_mmap_map *map,
}
EXPORT_SYMBOL(sbusfb_mmap_helper);
-int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg,
- struct fb_info *info,
- int type, int fb_depth, unsigned long fb_size)
+static int sbufsfb_ioctl_gtype(struct fbtype __user *f, struct fb_info *info,
+ int type, int fb_depth, unsigned long fb_size)
{
- switch(cmd) {
- case FBIOGTYPE: {
- struct fbtype __user *f = (struct fbtype __user *) arg;
-
- if (put_user(type, &f->fb_type) ||
- put_user(info->var.yres, &f->fb_height) ||
- put_user(info->var.xres, &f->fb_width) ||
- put_user(fb_depth, &f->fb_depth) ||
- put_user(0, &f->fb_cmsize) ||
- put_user(fb_size, &f->fb_cmsize))
- return -EFAULT;
- return 0;
- }
- case FBIOPUTCMAP_SPARC: {
- struct fbcmap __user *c = (struct fbcmap __user *) arg;
- struct fb_cmap cmap;
- u16 red, green, blue;
- u8 red8, green8, blue8;
- unsigned char __user *ured;
- unsigned char __user *ugreen;
- unsigned char __user *ublue;
- unsigned int index, count, i;
-
- if (get_user(index, &c->index) ||
- get_user(count, &c->count) ||
- get_user(ured, &c->red) ||
- get_user(ugreen, &c->green) ||
- get_user(ublue, &c->blue))
+ if (put_user(type, &f->fb_type) ||
+ put_user(info->var.yres, &f->fb_height) ||
+ put_user(info->var.xres, &f->fb_width) ||
+ put_user(fb_depth, &f->fb_depth) ||
+ put_user(fb_size, &f->fb_cmsize))
+ return -EFAULT;
+ return 0;
+}
+
+static int sbusfb_ioctl_putcmap(struct fbcmap *c, struct fb_info *info)
+{
+ u8 red8, green8, blue8;
+ u16 red, green, blue;
+ struct fb_cmap cmap;
+ unsigned int i;
+ int err;
+
+ cmap.len = 1;
+ cmap.red = &red;
+ cmap.green = &green;
+ cmap.blue = &blue;
+ cmap.transp = NULL;
+ for (i = 0; i < c->count; i++) {
+ if (get_user(red8, c->red + i) ||
+ get_user(green8, c->green + i) ||
+ get_user(blue8, c->blue + i))
return -EFAULT;
- cmap.len = 1;
- cmap.red = &red;
- cmap.green = &green;
- cmap.blue = &blue;
- cmap.transp = NULL;
- for (i = 0; i < count; i++) {
- int err;
-
- if (get_user(red8, &ured[i]) ||
- get_user(green8, &ugreen[i]) ||
- get_user(blue8, &ublue[i]))
- return -EFAULT;
-
- red = red8 << 8;
- green = green8 << 8;
- blue = blue8 << 8;
-
- cmap.start = index + i;
- err = fb_set_cmap(&cmap, info);
- if (err)
- return err;
- }
- return 0;
+ red = red8 << 8;
+ green = green8 << 8;
+ blue = blue8 << 8;
+
+ cmap.start = c->index + i;
+ err = fb_set_cmap(&cmap, info);
+ if (err)
+ return err;
}
- case FBIOGETCMAP_SPARC: {
- struct fbcmap __user *c = (struct fbcmap __user *) arg;
- unsigned char __user *ured;
- unsigned char __user *ugreen;
- unsigned char __user *ublue;
- struct fb_cmap *cmap = &info->cmap;
- unsigned int index, count, i;
- u8 red, green, blue;
-
- if (get_user(index, &c->index) ||
- get_user(count, &c->count) ||
- get_user(ured, &c->red) ||
- get_user(ugreen, &c->green) ||
- get_user(ublue, &c->blue))
- return -EFAULT;
+ return 0;
+}
- if (index > cmap->len || count > cmap->len - index)
- return -EINVAL;
-
- for (i = 0; i < count; i++) {
- red = cmap->red[index + i] >> 8;
- green = cmap->green[index + i] >> 8;
- blue = cmap->blue[index + i] >> 8;
- if (put_user(red, &ured[i]) ||
- put_user(green, &ugreen[i]) ||
- put_user(blue, &ublue[i]))
- return -EFAULT;
- }
- return 0;
+static int sbusfb_ioctl_getcmap(struct fbcmap *c, struct fb_info *info)
+{
+ unsigned int i;
+
+ if (c->index > info->cmap.len || c->count > info->cmap.len - c->index)
+ return -EINVAL;
+
+ for (i = 0; i < c->count; i++) {
+ u8 red = info->cmap.red[c->index + i] >> 8;
+ u8 green = info->cmap.green[c->index + i] >> 8;
+ u8 blue = info->cmap.blue[c->index + i] >> 8;
+
+ if (put_user(red, c->red + i) ||
+ put_user(green, c->green + i) ||
+ put_user(blue, c->blue + i))
+ return -EFAULT;
}
+ return 0;
+}
+
+int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg,
+ struct fb_info *info,
+ int type, int fb_depth, unsigned long fb_size)
+{
+ void __user *argp = (void __user *)arg;
+ struct fbcmap kc;
+
+ switch (cmd) {
+ case FBIOGTYPE:
+ return sbufsfb_ioctl_gtype(argp, info, type, fb_depth, fb_size);
+ case FBIOPUTCMAP_SPARC:
+ if (copy_from_user(&kc, argp, sizeof(kc)))
+ return -EFAULT;
+ return sbusfb_ioctl_putcmap(&kc, info);
+ case FBIOGETCMAP_SPARC:
+ if (copy_from_user(&kc, argp, sizeof(kc)))
+ return -EFAULT;
+ return sbusfb_ioctl_getcmap(&kc, info);
default:
return -EINVAL;
}
--
2.28.0
next prev parent reply other threads:[~2020-10-07 7:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-07 7:44 fbdev sbuslib cleanups Christoph Hellwig
2020-10-07 7:44 ` [PATCH 1/3] fbdev/sbuslib: remove FBIOSCURSOR/FBIOGCURSOR leftovers Christoph Hellwig
2020-10-07 8:05 ` Geert Uytterhoeven
2020-10-07 8:54 ` Arnd Bergmann
2020-10-07 8:59 ` Christoph Hellwig
2020-10-07 9:28 ` Arnd Bergmann
2020-10-07 10:40 ` Christoph Hellwig
2020-10-07 11:07 ` Arnd Bergmann
2020-10-07 15:41 ` Sam Ravnborg
2020-10-07 7:44 ` Christoph Hellwig [this message]
2020-10-07 7:44 ` [PATCH 3/3] fbdev/sbuslib: avoid compat_alloc_user_space in fbiogetputcmap Christoph Hellwig
2020-10-07 9:14 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201007074447.797968-3-hch@lst.de \
--to=hch@lst.de \
--cc=arnd@arndb.de \
--cc=b.zolnierkie@samsung.com \
--cc=davem@davemloft.net \
--cc=geert@linux-m68k.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=sparclinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).