From patchwork Fri Sep 23 16:38:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9348461 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DD94D601C2 for ; Fri, 23 Sep 2016 16:38:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEBE92ABBC for ; Fri, 23 Sep 2016 16:38:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2E0B2AC6F; Fri, 23 Sep 2016 16:38:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5603D2ABBC for ; Fri, 23 Sep 2016 16:38:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CA5DE6EAEB; Fri, 23 Sep 2016 16:38:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.web.de (mout.web.de [212.227.15.14]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8AE956EAEB for ; Fri, 23 Sep 2016 16:38:11 +0000 (UTC) Received: from [192.168.1.2] ([77.182.222.137]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0LtWsu-1amt0D0EFA-010w4n; Fri, 23 Sep 2016 18:38:05 +0200 Subject: [PATCH 2/3] drm/vmwgfx: Use memdup_user() rather than duplicating its implementation To: dri-devel@lists.freedesktop.org, linux-graphics-maintainer@vmware.com, David Airlie , Sinclair Yeh , Thomas Hellstrom References: <8de6f7c3-5614-b210-7b2f-66c1aed4279b@users.sourceforge.net> From: SF Markus Elfring Message-ID: <4949fd96-a27f-1694-823e-a401abbe032e@users.sourceforge.net> Date: Fri, 23 Sep 2016 18:38:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <8de6f7c3-5614-b210-7b2f-66c1aed4279b@users.sourceforge.net> X-Provags-ID: V03:K0:PETKkQKsSPK0nniDj461sLbp6ILJ9AXAT1u7mlzF++foJxNVVvP lDpvTH37NpnBKpfQuIUia0BbOgim9S/HSbZEdJLor4Of8CQB2iS+dBy4M08mJoJBT+QAu8h Z6fYBh0GNtwlJ6tCrr4KgBRcVXzeDtzWRoe8pLjJAspMYz37/Hd7T4B2m6mxoyLjHnv6JC0 gBu02tjNYYB8uJ2P/hmbQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:l9xyAk1HCPc=:9LTZ59a+yKsxe6M4Dqgu/C iYj7fHqkAtTgZLNuo1l+SDCFfgp4qjz9iRxyNYGhPrVktq3ZXyuEudNlTtSk9i/fqTlrHXpI+ FL6VioXznY2/gsrbQhILrMppiwRWJ5f0S0HS0xKCyEjlaBoBe0d/OTg16DMjfiiqkFaFm1QgO /Ox0Nw+EZrt+Saku6UJYK4WqopMTPfjik4gYzzJxySS1X14375NsQq/dKu2hkT2lAtDV9Oh3d L0F0Rwr/IMyaOdyGXcPZtp88bls2iw29XbtZ+farhYiXzWMQuehA6PjtdPsCmsNmtVKPlw9Re FfTvrfr0STx6qh1sH0D7YL9ql7tvFYh6tpM2mfto3lQZlWGxnGOamoOM+tGK1fZFYy9NzN97Q CHWf+O5uk7Q7j1Ukz70e+VsEdCHiucCuLbsXmB+88n4LEzhI38LgSIXxBBFJ7CUiCH+D13lkN 9gLaqMUjWuojGITJCTmr2E4N5qcX7Qs44We0ProDFFFZR6yHwR7MZCLud7zt6pr4goumybNxf vL8ZcUNfYy8WrQUuxCZJuJ6nyu5clPqaH9AlzkJDwwjprR34GXGNaVntvWffzZy7doQnjrKmi eUmnPbU2yLVbnLVp081xONiWHIfGOwA1fIexSL4Yb14TnQO0EthA4R3NGNPyEriPrZHmg3jB5 rXdIqvvLJtN9n6PNw65iARdDJxNTQVE4bQR0Kf8ZF1UHDVEEoydHB53l1bElsCQmnuiH3HDte +D4N8XxH5LMGKmsb3U4NpN1SS/diQXVAku4psb5VlF+0lXDsTyVH51xuCuZrzTik9UiTFPO7O 9SRH+3A Cc: Julia Lawall , kernel-janitors@vger.kernel.org, LKML X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Fri, 23 Sep 2016 17:26:02 +0200 * Reuse existing functionality from memdup_user() instead of keeping duplicate source code. * Try this copy operation before allocating memory for the data structure member "offsets". * Delete the local variable "user_sizes" which became unnecessary with this refactoring. Signed-off-by: Markus Elfring --- drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c index f557549..15504c6 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_surface.c @@ -700,7 +700,6 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, struct drm_vmw_surface_create_req *req = &arg->req; struct drm_vmw_surface_arg *rep = &arg->rep; struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; - struct drm_vmw_size __user *user_sizes; int ret; int i, j; uint32_t cur_bo_offset; @@ -763,11 +762,11 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, memcpy(srf->mip_levels, req->mip_levels, sizeof(srf->mip_levels)); srf->num_sizes = num_sizes; user_srf->size = size; - srf->sizes = kmalloc_array(srf->num_sizes, - sizeof(*srf->sizes), - GFP_KERNEL); - if (unlikely(srf->sizes == NULL)) { - ret = -ENOMEM; + srf->sizes = memdup_user((struct drm_vmw_size __user *)(unsigned long) + req->size_addr, + sizeof(*srf->sizes) * srf->num_sizes); + if (IS_ERR(srf->sizes)) { + ret = PTR_ERR(srf->sizes); goto out_no_sizes; } srf->offsets = kmalloc_array(srf->num_sizes, @@ -778,16 +777,6 @@ int vmw_surface_define_ioctl(struct drm_device *dev, void *data, goto out_no_offsets; } - user_sizes = (struct drm_vmw_size __user *)(unsigned long) - req->size_addr; - - ret = copy_from_user(srf->sizes, user_sizes, - srf->num_sizes * sizeof(*srf->sizes)); - if (unlikely(ret != 0)) { - ret = -EFAULT; - goto out_no_copy; - } - srf->base_size = *srf->sizes; srf->autogen_filter = SVGA3D_TEX_FILTER_NONE; srf->multisample_count = 0;