From patchwork Fri Aug 19 08:17:16 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: 9289775 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 D67E1607FF for ; Fri, 19 Aug 2016 08:17:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8D0A29336 for ; Fri, 19 Aug 2016 08:17:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD62229338; Fri, 19 Aug 2016 08:17:53 +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=unavailable 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 27F5E29337 for ; Fri, 19 Aug 2016 08:17:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754830AbcHSIRl (ORCPT ); Fri, 19 Aug 2016 04:17:41 -0400 Received: from mout.web.de ([212.227.15.14]:56079 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750731AbcHSIRi (ORCPT ); Fri, 19 Aug 2016 04:17:38 -0400 Received: from [192.168.1.3] ([77.181.218.203]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0MD8VY-1bOcqE0MOK-00GVZ7; Fri, 19 Aug 2016 10:17:22 +0200 To: linux-media@vger.kernel.org, Abhilash Jindal , Mauro Carvalho Chehab , Max Kellermann , Michael Ira Krufky , Shuah Khan From: SF Markus Elfring Subject: [PATCH] [media] dvb_frontend: Use memdup_user() rather than duplicating its implementation Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall Message-ID: <40f67371-815d-ad02-7bf7-db9998da0262@users.sourceforge.net> Date: Fri, 19 Aug 2016 10:17:16 +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:bYvOMOnew4kWiE1qe83V8w3A0gX1bm+rNAIAr3DtBUNHAXB+PXj s3ug+z8ulGirIpo6GckqVdCkPlLF0kXf+dF6IsMd1NdtEQbYkwIomSmfZUtAkw3U4bwlP6u WyZY0xrzdO8Js4RMsQP+GemZum8rQ2AtcvIJ+WA8ECsUfofyroXVC/vG3kzV9H9cSvifbpp Fij5D3kUws1TZQG5gRS2w== X-UI-Out-Filterresults: notjunk:1; V01:K0:ry0cLYhE6G4=:iUREisGV/xxPfDIWcYNF9r qECFp8yl+n8Ux6cg+4bnRjlZHnqFY1KS2A/cQ5kSWSgHfvbkSGYLLZq8TLRRHKIb7hroRP018 3nwBNHDTlxmgcDqEkRQS+6Q/xZYFmpkvv0Qic41mBf6mE4QTeuKEd3c1pQ6/6Gj8vIBqSpJFG YKTEj47QL+dJPQ5HzX9ZqG2EDhPPcidfrxex4NkG1pVUY0a56z/5TsjQUDLSTBtAogHuzdaEv k11tLhSVuNMWFk6z7jYZp/bXJCfxi07Bl9hC7QJixOfXLOx5XTcKBki6ocgH7J0w3saDZSbjX JrfogS7pJKl9iX0T6bWRZdsygYB9rbg+qGPwIMkUObiqSSDNo7aKlIG1MNYI8tUFFm7/QCRJ8 icueIbH8YQjvwf0bqhEgzNht61cPIdKsuiuGKDVrw2/FCZJNhfzid5zqoSgNvDh9ILBolRM1J 32NXmhLEbYImigIHl1TAKQ4ZrWQw8BcH1bCAw/w8zFSmFWClvi1ouW2mnXgXgB2dcjpxpM9Dv QnsWzxI4kqfwaXBWiuXz2Hm9u+C1wN+IgAYR+h43tCORkZ/sojgn7L6M9vZ1e6YssLZOitlSd ASqHybRKFANanyVi09JrHKy3wAkw1SI8il5gOPm1LOqaz6smKE6evAvvDCKFJ5I0Aw8AYBu7n PSBOr+J9D5IcJ40Z/HfG1qLIEXqpwA/ZQwJ/scx0SYonoSHC4uajYeSv8QQNDaJxoq+PWy0Z5 Ru7zzVbFqztvYSWXaLmWgA75GTEpHi/TddRyudCjaR+0dXzcr57KQUVAM4PTyJoGOtwOm4u63 aGCA6KU 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:04:54 +0200 * Reuse existing functionality from memdup_user() instead of keeping duplicate source code. This issue was detected by using the Coccinelle software. * Return directly if this copy operation failed. * Replace the specification of data structures by pointer dereferences to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring --- drivers/media/dvb-core/dvb_frontend.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c index be99c8d..01511e5 100644 --- a/drivers/media/dvb-core/dvb_frontend.c +++ b/drivers/media/dvb-core/dvb_frontend.c @@ -1969,17 +1969,9 @@ static int dvb_frontend_ioctl_properties(struct file *file, if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) return -EINVAL; - tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL); - if (!tvp) { - err = -ENOMEM; - goto out; - } - - if (copy_from_user(tvp, (void __user *)tvps->props, - tvps->num * sizeof(struct dtv_property))) { - err = -EFAULT; - goto out; - } + tvp = memdup_user(tvps->props, tvps->num * sizeof(*tvp)); + if (IS_ERR(tvp)) + return PTR_ERR(tvp); for (i = 0; i < tvps->num; i++) { err = dtv_property_process_set(fe, tvp + i, file); @@ -2002,17 +1994,9 @@ static int dvb_frontend_ioctl_properties(struct file *file, if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS)) return -EINVAL; - tvp = kmalloc(tvps->num * sizeof(struct dtv_property), GFP_KERNEL); - if (!tvp) { - err = -ENOMEM; - goto out; - } - - if (copy_from_user(tvp, (void __user *)tvps->props, - tvps->num * sizeof(struct dtv_property))) { - err = -EFAULT; - goto out; - } + tvp = memdup_user(tvps->props, tvps->num * sizeof(*tvp)); + if (IS_ERR(tvp)) + return PTR_ERR(tvp); /* * Let's use our own copy of property cache, in order to