From patchwork Fri Aug 19 09:23:18 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: 9289893 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 E397D60574 for ; Fri, 19 Aug 2016 09:23:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D31C729348 for ; Fri, 19 Aug 2016 09:23:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C774D29376; Fri, 19 Aug 2016 09:23:52 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6392B29348 for ; Fri, 19 Aug 2016 09:23:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753813AbcHSJXe (ORCPT ); Fri, 19 Aug 2016 05:23:34 -0400 Received: from mout.web.de ([212.227.15.3]:56183 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752581AbcHSJXd (ORCPT ); Fri, 19 Aug 2016 05:23:33 -0400 Received: from [192.168.1.3] ([77.181.218.203]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0MYO5B-1bfIkf3eSX-00VA7M; Fri, 19 Aug 2016 11:23:24 +0200 Subject: [PATCH 1/2] uvc_v4l2: Use memdup_user() rather than duplicating its implementation To: linux-media@vger.kernel.org, Laurent Pinchart , Mauro Carvalho Chehab References: <566ABCD9.1060404@users.sourceforge.net> <95aa5fcd-8610-debc-70b0-30b2ed3302d2@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: <4181a4b7-3527-4ddf-4c7f-42fcd47977ca@users.sourceforge.net> Date: Fri, 19 Aug 2016 11:23:18 +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: <95aa5fcd-8610-debc-70b0-30b2ed3302d2@users.sourceforge.net> X-Provags-ID: V03:K0:jBE+y0vSwSSyiJcPS68Af+wjG2Rz3YUx5o6s6JBpWAgLVtEWdSR p1ogZCPsK3dFlSOXppybqcPqC86FQTEkp8Jb/2QDUhfq1NNyKzN+T6uV+xl7LYi6rqamf+3 qYhdEfv+KIVK+SUaAahPtnhDnF+Oxs0rsgmPTTqTHntihsmbUSiuAIgE4j0bB14paxBNNDK 3SqEgbIu6+gTJGzkFA/aA== X-UI-Out-Filterresults: notjunk:1; V01:K0:4uurvDvaaPw=:eE6FD6Kea8BDxi8OSREg+x 9XquAcbLrL5IBx88jmpOdDoIq7dVksqtaR/8tdLJw4KxXc/ueBjI5AqF6BGreJArDJH+iCdiT 3cejI3thldPktYooeDE9OzGZEzORD1aL5UkxfWnHuupjKVS38bLWWrLZXOvHqw7ql3wo76EEQ xnKPEOfWlZHu7c12vM8Ph/fmGWAmhBAP+Tdg5z88FD1w02zeGUYfmVdxuBspsKD1sawDYr+ru KX2qyFS/r4FX8GxipxqcK4dxBp35lkaWChUMcAjvMntPYwEdjPfuJRbsspNXMDNQRsNyw43QR YstizL7QgzssZqctM/bXZXjz0MmrIlwn0wMIdvqCZFFe70WLsM7tZzOeMS/7KM8eRTgJeVRZg H81JQi+9N3sX6qnxhRgS1rxwGcZtici96Vb16HneQzvHIfX7sVeIDnhmVPjP6TO6rtrj+oHs9 uF3VDgAXCaCKDoOztBCH9Hqu6nGKIdnZwqOVE5Fm1Rg8e9NsTyeRS6RNOpSIRrN+g0t1qfpP0 JOnn8smrbH1fk7T5jayb+KNWoML0WQ/kWX+29sorNr0p1mNo2PFMx5Htof/r7IGCVALlo8qoU UvsGjmB3W9VfC3rLnwdBSTIdwNs3pG8fmL69VlroPBSdB3sv8F14IcGS8WOAY+Sr3UAydVUdt pzV36EGnh5LDyeJPQ6mV9T6dlWqLx0EWCx8r5ttHFgmR+GUTblGTGSN8BmHYpPu4bif1uo0bi WjgWJsS7tVNFHoWt4hFd7n9t8o4NbdXK1y6gg41dHYLTISidMuR1Q6CdAf3taXb0k2GU7PsmF RGaKXo/ Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Fri, 19 Aug 2016 10:50:05 +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 Reviewed-by: Laurent Pinchart --- drivers/media/usb/uvc/uvc_v4l2.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 05eed4b..a7e12fd 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -70,14 +70,9 @@ static int uvc_ioctl_ctrl_map(struct uvc_video_chain *chain, } size = xmap->menu_count * sizeof(*map->menu_info); - map->menu_info = kmalloc(size, GFP_KERNEL); - if (map->menu_info == NULL) { - ret = -ENOMEM; - goto done; - } - - if (copy_from_user(map->menu_info, xmap->menu_info, size)) { - ret = -EFAULT; + map->menu_info = memdup_user(xmap->menu_info, size); + if (IS_ERR(map->menu_info)) { + ret = PTR_ERR(map->menu_info); goto done; }