From patchwork Fri Sep 18 10:09:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 313173 Delivered-To: patch@linaro.org Received: by 2002:a92:5ad1:0:0:0:0:0 with SMTP id b78csp1182412ilg; Fri, 18 Sep 2020 03:15:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrh8IxbqvYH/zCiatZKZ+qugkkBtCtb/NNkUNsb3/0tuoMiEm/7YvUuyeyEmLLFiOGkCIZ X-Received: by 2002:a17:906:28c4:: with SMTP id p4mr34862600ejd.345.1600424106964; Fri, 18 Sep 2020 03:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600424106; cv=none; d=google.com; s=arc-20160816; b=EqaZ5Xnv1ekHYsZiihLFppvS72ZiG8HiLixgwl0NW8cUN9EU93zffRP+p3bDY3CG1Q 7WxRMhjYtQKFbfWia1sM+VrOU+y0oD2WWjypQdSIRJi54JDz7FxXDp5Wjgl+WgogkHYQ s6nPOFdmoSNFZb9b8AXJua+Y79I3GNtfJVn/fOFeOiIj6ZF1hBv2LeFxGmBy8YxXLa0M QeaCWjIAbXHqeCnPsulusFLRyZ7NTbV0Il3LC9f3i97uKrqBu9i8R+WxZ/MQz0pvnPkS COXRjEnVyu/PAXe8bQZUyPBzFVHOCY8XX5LSqHO6JC6jdRc8OWf8YBs7Z8rzv7NkFfcU yP0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=8hibOwJYpahRlPegJxKtSSTrbNZ3YaydYAPS5sITCr0=; b=bAAeLY1qsP1cva12nUsHCW/ESv66v4GE6ZgNbAteOtMl2opLvR76+Uy4tN2cM0kaEG hJcl8PXsNYC02j1Qd2liYuhhLK1uL7M3+F+ozxnpdNJK0BJMu1tpfz4YA/LUtW6WODH/ QAHv8S6FRh41N+rPPv7CKRFW0z4WdUUD5sLlzo+de+RAKVzL97FW7onL6GIJMrQgLt8d fN8g/yAjK0hlB5A7A1lEJPOIxbmfxvKS8nsY+1LJrUzfqxQUvubfbJD7iC4J4cmOiyQS DAm4sVMuMCkR0OJ4EQyF7oBqPz8K8o4nvpjl+JNwQKFpEJwb827QXbgB4y84zcmbH+1e N+Og== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-fbdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-fbdev-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mf3si1793669ejb.27.2020.09.18.03.15.06 for ; Fri, 18 Sep 2020 03:15:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-fbdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-fbdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-fbdev-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726310AbgIRKPG (ORCPT ); Fri, 18 Sep 2020 06:15:06 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:36411 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726130AbgIRKPG (ORCPT ); Fri, 18 Sep 2020 06:15:06 -0400 Received: from threadripper.lan ([149.172.98.151]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.129]) with ESMTPA (Nemesis) id 1MfHQp-1kzioY3oj5-00gtZg; Fri, 18 Sep 2020 12:09:33 +0200 From: Arnd Bergmann To: linux-fbdev@vger.kernel.org, Bartlomiej Zolnierkiewicz Cc: dri-devel@lists.freedesktop.org, hch@lst.de, linux-kernel@vger.kernel.org, "David S . Miller" , Arnd Bergmann , Daniel Vetter , Geert Uytterhoeven Subject: [PATCH 1/3] fbdev: simplify fb_getput_cmap() Date: Fri, 18 Sep 2020 12:09:04 +0200 Message-Id: <20200918100926.1447563-1-arnd@arndb.de> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200918100812.1447443-1-arnd@arndb.de> References: <20200918100812.1447443-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:qTgjU2sPJm0CtwAKfelk8EKx/cY7OswKlwGh4NJZIDPMM4UJmUa ApsbULj9LW7rbHjUIz1A/i0NUp0GCZEkUeR45RFfhJofLOW7W5UZQXrFwxabzkSPKBUC3O4 4iyxGZQkD/CfW/upMjj+If3hjxf2OaTt5NAhb6N8DJtpZgN492yoUHypNo5oZFBnV+Jkf0L 8qjEN/cBHKUVWweeaMiHg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:6wF6uVnDOQo=:ydcIg5CETGJHzt0PPH4E2E YbUXatWHgJwD0EqPEeTOi3ak8UUTuYozvYbcKahQBMyi7dltkRoLyfO53QW29YOWbsfvqgLj3 7NFX0ungQuu6SxjXrn0NGWOQq6nNQ6Ec4O/O14N8DAYdJpfSxBY30suqlpfTBZ++TfDu4B/ab x3yh4vOtgbx634lgCx4G5FgaWbIuW2ReDfBqPQ1ll/6HflmwzrAAwx84f+trHqOYgarUCaPeI Q9Vg8k9Nnql4xioyGlNawD9L5/7go6FM9h82K1p+korWv83KSDeY3oxPjm7CfZMvwY8Y0B2GF HiIBT0Jj3tpvoJ6dpWaBP7/zAZQM7LDwD5xbyEw1lk1bIWFNCaYV0kVjtsZB1XWLc57mptlLJ hhB5KkFUvxCuYBJ4vOP11GMJ6jYkxWImgKqkWxADtRexyaMprt82jvx2dnGWhCfrwBRQmDk5p fJ5h3+/ZS2Lvbv/HZBNUbJN/lABvKc7oNi5nL8BqxSoGjscHfcih2y5OFvCY5asaw+LoggZ7O hEsbPLxM1dfCC437Z9vyvBwRxDaJfq7q0aOaf89riv01rZAn29mduAVXdZSwpRgyPayhaVjhr wdV5RNf/EpXG1lNVmbNBG618uJuc85NKY7L0kCtfqqGIIhU2ZtTumnoUmyWJVL/K/lV4ej93L fqHdFcYChfwyeFxOupbIZPvoc2PLk9nL8DGSQVXBxw4oRgBYCYSZqpH7ApugrbJJKn9R32rlw g+zN2RBJ4UF/6cDMyydNsY3O2Eu/Li0p2vPGOGZETpH/Prnwa7IRYaRb52puX2tokLaia/oEC DeGAcZ3g+63nPmRGEECK1mXZ+6xyOj4pt1/MbiKh7slvKDwRvMTib3FGwgGjUkY3NmFtqHm Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org 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 --- drivers/video/fbdev/core/fbmem.c | 44 ++++++++++++++------------------ 1 file changed, 19 insertions(+), 25 deletions(-) -- 2.27.0 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c index da7c88ffaa6a..4e162e3d3538 100644 --- a/drivers/video/fbdev/core/fbmem.c +++ b/drivers/video/fbdev/core/fbmem.c @@ -1211,36 +1211,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, From patchwork Fri Sep 18 10:09:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 293250 From: Arnd Bergmann Date: Fri, 18 Sep 2020 10:09:05 +0000 Subject: [PATCH 2/3] fbdev: sbuslib: remove unused FBIOSCURSOR32 helper Message-Id: <20200918100926.1447563-2-arnd@arndb.de> List-Id: References: <20200918100812.1447443-1-arnd@arndb.de> In-Reply-To: <20200918100812.1447443-1-arnd@arndb.de> MIME-Version: 1.0 To: linux-fbdev@vger.kernel.org, Bartlomiej Zolnierkiewicz Cc: "David S . Miller" , Arnd Bergmann , hch@lst.de, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org No driver implements FBIOSCURSOR, so this function has no purpose and can be removed. Apparently it was added in linux-2.1.44 to handle compatibility for drivers/sbus/char/sunfb.c but lost its purpose when that driver got rewritten in linux-2.5.63. Signed-off-by: Arnd Bergmann --- drivers/video/fbdev/sbuslib.c | 29 +---------------------------- 1 file changed, 1 insertion(+), 28 deletions(-) diff --git a/drivers/video/fbdev/sbuslib.c b/drivers/video/fbdev/sbuslib.c index 01a7110e61a7..f728db9bcff8 100644 --- a/drivers/video/fbdev/sbuslib.c +++ b/drivers/video/fbdev/sbuslib.c @@ -214,32 +214,6 @@ static int fbiogetputcmap(struct fb_info *info, unsigned int cmd, unsigned long (unsigned long)p); } -static int fbiogscursor(struct fb_info *info, unsigned long arg) -{ - struct fbcursor __user *p = compat_alloc_user_space(sizeof(*p)); - struct fbcursor32 __user *argp = (void __user *)arg; - compat_uptr_t addr; - int ret; - - ret = copy_in_user(p, argp, - 2 * sizeof (short) + 2 * sizeof(struct fbcurpos)); - ret |= copy_in_user(&p->size, &argp->size, sizeof(struct fbcurpos)); - ret |= copy_in_user(&p->cmap, &argp->cmap, 2 * sizeof(int)); - ret |= get_user(addr, &argp->cmap.red); - ret |= put_user(compat_ptr(addr), &p->cmap.red); - ret |= get_user(addr, &argp->cmap.green); - ret |= put_user(compat_ptr(addr), &p->cmap.green); - ret |= get_user(addr, &argp->cmap.blue); - ret |= put_user(compat_ptr(addr), &p->cmap.blue); - ret |= get_user(addr, &argp->mask); - ret |= put_user(compat_ptr(addr), &p->mask); - ret |= get_user(addr, &argp->image); - ret |= put_user(compat_ptr(addr), &p->image); - if (ret) - return -EFAULT; - return info->fbops->fb_ioctl(info, FBIOSCURSOR, (unsigned long)p); -} - int sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { switch (cmd) { @@ -248,6 +222,7 @@ int sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, unsigned long ar case FBIOGATTR: case FBIOSVIDEO: case FBIOGVIDEO: + case FBIOSCURSOR32: case FBIOGCURSOR32: /* This is not implemented yet. Later it should be converted... */ case FBIOSCURPOS: @@ -258,8 +233,6 @@ int sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, unsigned long ar return fbiogetputcmap(info, cmd, arg); case FBIOGETCMAP32: return fbiogetputcmap(info, cmd, arg); - case FBIOSCURSOR32: - return fbiogscursor(info, arg); default: return -ENOIOCTLCMD; } From patchwork Fri Sep 18 10:09:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 293241 From: Arnd Bergmann Date: Fri, 18 Sep 2020 10:09:06 +0000 Subject: [PATCH 3/3] fbdev: sbuslib: remove compat_alloc_user_space usage Message-Id: <20200918100926.1447563-3-arnd@arndb.de> List-Id: References: <20200918100812.1447443-1-arnd@arndb.de> In-Reply-To: <20200918100812.1447443-1-arnd@arndb.de> MIME-Version: 1.0 To: linux-fbdev@vger.kernel.org, Bartlomiej Zolnierkiewicz Cc: "David S . Miller" , Arnd Bergmann , hch@lst.de, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org This is one of the last users of compat_alloc_user_space() and copy_in_user(). The actual handler is implemented in the same file and could be shared, but as I couldn't test this properly I leave the native case alone and just make a straight copy of it for the compat case, with a minimum set of modifications. Signed-off-by: Arnd Bergmann --- drivers/video/fbdev/sbuslib.c | 95 ++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 25 deletions(-) diff --git a/drivers/video/fbdev/sbuslib.c b/drivers/video/fbdev/sbuslib.c index f728db9bcff8..da28c279a54b 100644 --- a/drivers/video/fbdev/sbuslib.c +++ b/drivers/video/fbdev/sbuslib.c @@ -192,28 +192,6 @@ int sbusfb_ioctl_helper(unsigned long cmd, unsigned long arg, EXPORT_SYMBOL(sbusfb_ioctl_helper); #ifdef CONFIG_COMPAT -static int fbiogetputcmap(struct fb_info *info, unsigned int cmd, unsigned long arg) -{ - struct fbcmap32 __user *argp = (void __user *)arg; - struct fbcmap __user *p = compat_alloc_user_space(sizeof(*p)); - u32 addr; - int ret; - - ret = copy_in_user(p, argp, 2 * sizeof(int)); - ret |= get_user(addr, &argp->red); - ret |= put_user(compat_ptr(addr), &p->red); - ret |= get_user(addr, &argp->green); - ret |= put_user(compat_ptr(addr), &p->green); - ret |= get_user(addr, &argp->blue); - ret |= put_user(compat_ptr(addr), &p->blue); - if (ret) - return -EFAULT; - return info->fbops->fb_ioctl(info, - (cmd = FBIOPUTCMAP32) ? - FBIOPUTCMAP_SPARC : FBIOGETCMAP_SPARC, - (unsigned long)p); -} - int sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { switch (cmd) { @@ -230,9 +208,76 @@ int sbusfb_compat_ioctl(struct fb_info *info, unsigned int cmd, unsigned long ar case FBIOGCURMAX: return info->fbops->fb_ioctl(info, cmd, arg); case FBIOPUTCMAP32: - return fbiogetputcmap(info, cmd, arg); - case FBIOGETCMAP32: - return fbiogetputcmap(info, cmd, arg); + case FBIOPUTCMAP_SPARC: { + struct fbcmap32 c; + 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 i; + + if (copy_from_user(&c, compat_ptr(arg), sizeof(c))) + return -EFAULT; + ured = compat_ptr(c.red); + ugreen = compat_ptr(c.green); + ublue = compat_ptr(c.blue); + + cmap.len = 1; + cmap.red = &red; + cmap.green = &green; + cmap.blue = &blue; + cmap.transp = NULL; + for (i = 0; i < c.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 = c.index + i; + err = fb_set_cmap(&cmap, info); + if (err) + return err; + } + return 0; + } + case FBIOGETCMAP32: { + struct fbcmap32 c; + unsigned char __user *ured; + unsigned char __user *ugreen; + unsigned char __user *ublue; + struct fb_cmap *cmap = &info->cmap; + unsigned int index, i; + u8 red, green, blue; + + if (copy_from_user(&c, compat_ptr(arg), sizeof(c))) + return -EFAULT; + index = c.index; + ured = compat_ptr(c.red); + ugreen = compat_ptr(c.green); + ublue = compat_ptr(c.blue); + + if (index > cmap->len || c.count > cmap->len - index) + return -EINVAL; + + for (i = 0; i < c.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; + } default: return -ENOIOCTLCMD; }