From patchwork Thu Aug 18 20:42:06 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: 9288631 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 DB64560574 for ; Thu, 18 Aug 2016 20:42:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC39F28BB2 for ; Thu, 18 Aug 2016 20:42:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0D6428BD4; Thu, 18 Aug 2016 20:42:26 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 6DE4828BB2 for ; Thu, 18 Aug 2016 20:42:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5758D6E330; Thu, 18 Aug 2016 20:42:25 +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.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id C5CA26E330 for ; Thu, 18 Aug 2016 20:42:23 +0000 (UTC) Received: from [192.168.1.3] ([77.182.223.38]) by smtp.web.de (mrweb001) with ESMTPSA (Nemesis) id 0MOB3E-1bUxph3tHo-005bSk; Thu, 18 Aug 2016 22:42:14 +0200 To: dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, David Airlie , Gerd Hoffmann From: SF Markus Elfring Subject: [PATCH] virtio-gpu: Use memdup_user() rather than duplicating its implementation Message-ID: <401e68fc-5515-7a7a-be2e-503dee676b34@users.sourceforge.net> Date: Thu, 18 Aug 2016 22:42:06 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 X-Provags-ID: V03:K0:twrtCrxKIkezG3gQufD0xnCDeRHD0peKder0ZLfnRMzaHg26ozt e2JQMainfqgSDnZ84bHsAEUYeVqLxiY5tMZAb+MzJp7IJtN0ncvNx2dsfE/k07Yk1QNtUX7 FwKCroQ/qpD+oA7h1EXghNze42ltLvSRelZUWpXd9/fu/sfTvOPEjlBzrt7MIUEhE8xRp7x 62DQsVZNUmsL3GF/VCxMg== X-UI-Out-Filterresults: notjunk:1; V01:K0:5+z6/UevZ/0=:p/lfyAu8N5WzyoX49k5VJ5 Fq7vxdKN3tAMJH2xM3+2+K5XXMA1YKJWrK+AicrplCpfwgwmY+q7MGFpTRFHix2LBmjCCV1rx VwwmMdOXHWx914irMrxlWGDUsmsBB6XokoOnZrzQChOVcf5yGE+Z4ijhkiNDW8bJrUp0EXbv4 2q6agfAhkcyvrJszJYCCVLsIExlLwUelZB+YGMGbeEs79BKJYrR+9FSUPlhHiJHT5QGLr8Sid SL57GKx86/8bgZGRrtjbXYbRYfPiTEQjPkYL3nR70NaMBgBkl8sNygaK1sh77WumoVWeGMkiH sa8bwqMuV2yW9lCiDZQCIFo75pbYZGK/bxhj8TmT0sSN21qxoDT3o1TQPb2sdlIYC2K/97De7 jD0GVpvidANiUiMekk/zJPROuRAYYYKMBR7USe2iGS8bYJOCPJ8hJKwpeHnzZ+ra9uFg/vZFR sKAF2CEe2ZfA6PHH/V1MaqJlB9ZRgULYh54m06AtgDnHV13U1Z5kP/bG7ItmV3/y+LYbq2gLV V0aYXR3sHmnoeGM68svurLDCLxsW+1NMcNI6DcMBb8oIfCss7gohDk7ud2RbnsmGpG58IhwQx pJ6YiJQXGNsIIz3P5gceCdEm++q4yN2SflqzBsxuAYP3s9YJIUzuIsdqYk3d20sRUNuzo4Ger d6blUSeLJZse+BaUZGXyan3N4TCwIEMmTTcFX/n2tryH7nZwm7fY6Cjm9gFKgxR04r/W4na8h ZY7//B+JQqQrFCwI+IPPzkNm2yZ52xN/Z5HcYWDvnIsNhPZo2NtLUFAfolx4z8baFCp1aNd7p UAgGk5J 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: Thu, 18 Aug 2016 22:35:14 +0200 Reuse existing functionality from memdup_user() instead of keeping duplicate source code. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/gpu/drm/virtio/virtgpu_ioctl.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/virtio/virtgpu_ioctl.c b/drivers/gpu/drm/virtio/virtgpu_ioctl.c index c046903..512e7cd 100644 --- a/drivers/gpu/drm/virtio/virtgpu_ioctl.c +++ b/drivers/gpu/drm/virtio/virtgpu_ioctl.c @@ -152,15 +152,10 @@ static int virtio_gpu_execbuffer(struct drm_device *dev, if (ret) goto out_free; - buf = kmalloc(exbuf->size, GFP_KERNEL); - if (!buf) { - ret = -ENOMEM; - goto out_unresv; - } - if (copy_from_user(buf, (void __user *)(uintptr_t)exbuf->command, - exbuf->size)) { - kfree(buf); - ret = -EFAULT; + buf = memdup_user((void __user *)(uintptr_t)exbuf->command, + exbuf->size); + if (IS_ERR(buf)) { + ret = PTR_ERR(buf); goto out_unresv; } virtio_gpu_cmd_submit(vgdev, buf, exbuf->size,