From patchwork Thu Aug 18 19:45:24 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: 9288621 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 5F92E607FF for ; Thu, 18 Aug 2016 19:45:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5042C28F5B for ; Thu, 18 Aug 2016 19:45:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 42DDD28F6D; Thu, 18 Aug 2016 19:45:44 +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 C1AAC28F5B for ; Thu, 18 Aug 2016 19:45:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2ADD16EB0D; Thu, 18 Aug 2016 19:45:42 +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.17.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id 10B196EB0D for ; Thu, 18 Aug 2016 19:45:39 +0000 (UTC) Received: from [192.168.1.3] ([77.182.223.38]) by smtp.web.de (mrweb102) with ESMTPSA (Nemesis) id 0Mg7I1-1bmtxq3YOL-00NO9M; Thu, 18 Aug 2016 21:45:35 +0200 Subject: [PATCH 1/2] GPU-DRM-Savage: Use memdup_user() rather than duplicating To: "dri-devel@lists.freedesktop.org" , Daniel Vetter , David Airlie References: <566ABCD9.1060404@users.sourceforge.net> <77052ac1-1933-49af-3ad8-6e0eecc1aafe@users.sourceforge.net> From: SF Markus Elfring Message-ID: <021efa32-c259-e799-a80e-630972291815@users.sourceforge.net> Date: Thu, 18 Aug 2016 21:45:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: <77052ac1-1933-49af-3ad8-6e0eecc1aafe@users.sourceforge.net> X-Provags-ID: V03:K0:AikSqB5IkAgPlVplVDDm1mTzUXSRXCW+JWmJJYDQ37tuHNMFvNg glpTBw78DP2h37hpotDnvdwplJf/LTvuK4GjPUPlUsF4zVjKQTvNCzLlsD8WbFW/CvYwLZM PHga28R04ziQEAxscpjYB9Ye3QsskCi6KWB9NQbz/LvRSZ/r5Yv0IIgwT9AX6I3/GAe1wjj yYP46qQZhQ5glnzz0yQ+Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:s5hFMFT5d8c=:hcf3M95NNTmsVTPRy9LA4T Dxia6nCpbNdj4CkTlO9qx+jvXsXNqtG5N8ANDybDZsj1dw6Od5n6yNS7IBqbAi2NYpbLDQlVE 99M6zlPJCjWa8cf28vlONJQ+pD4bDL0YhzpolEVj64eM0v3fcr3myvmeL2jZ1ZNlB5QopSkMC KGMKaD/DjM4E6HWsK3kTFFLcR8f6AZH0G6t71xjkShwKZ6MA9q6DF3tg/LqNtJF/vw2hgM9wO jQvyB4Sc1XWppVOEuYCkv8qfDMbemr2HPQqT0rwAmuVJQr5Xb4b2/KAVM35GExwIw3gei1s7o y8ycM3iiRZLOoER+6So6f3rqplHNuC63pEsC95URmELiNdKFxlGt0z1Stt0H52WXjtLB9xROO CcP7LFNRW1sEHjMbuAqh3Wn6Sx+575rhSpNg9CeGQrqCazjdFv6SD1LHWKP75k5lcYEMb8WS4 6nHhB5xSWcvWeIOLyoyXSO7lTL5jAIkCKI2lvyfN+24fOu+k4ahgIl1RKThGQbtvkqVJLICU4 It9PAqvYt2oGtMw7jdckNZyTZI8n6z/EKS4duMXlN7AnuwTSs6ZRigwYV6t3R8TRhnkqdc6og MCYcAYqJ44BLg8bHy/18PEJhF7WIyww9bdaUma6V1jqRFAb8aXGbR8vDXwr8dlJkZy7TN8Ncy f1/MbkR76PGas5FwdJl7Htzji50tHmpA0oaDTU+V/36nDYbOZfZfR+2IUlNHJj6Pvh9tREyvd Bjy6Kc7UdXw7WqSKo2hQ3BjVfFdr+6+LT516mzsl7vtndHsPw2rweDJO6iDM1isl/DbKENtR9 82ZH5hB 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 18:12:03 +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/savage/savage_state.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/savage/savage_state.c b/drivers/gpu/drm/savage/savage_state.c index c01ad0a..3dc0d8f 100644 --- a/drivers/gpu/drm/savage/savage_state.c +++ b/drivers/gpu/drm/savage/savage_state.c @@ -1001,15 +1001,9 @@ int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_ cmdbuf->cmd_addr = kcmd_addr; } if (cmdbuf->vb_size) { - kvb_addr = kmalloc(cmdbuf->vb_size, GFP_KERNEL); - if (kvb_addr == NULL) { - ret = -ENOMEM; - goto done; - } - - if (copy_from_user(kvb_addr, cmdbuf->vb_addr, - cmdbuf->vb_size)) { - ret = -EFAULT; + kvb_addr = memdup_user(cmdbuf->vb_addr, cmdbuf->vb_size); + if (IS_ERR(kvb_addr)) { + ret = PTR_ERR(kvb_addr); goto done; } cmdbuf->vb_addr = kvb_addr;