From patchwork Sun Aug 21 08:48:48 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: 9292105 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 C5BE4607F0 for ; Sun, 21 Aug 2016 08:49:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5031289FA for ; Sun, 21 Aug 2016 08:49:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9DAD28A50; Sun, 21 Aug 2016 08:49:28 +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 6171C289FA for ; Sun, 21 Aug 2016 08:49:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752443AbcHUItJ (ORCPT ); Sun, 21 Aug 2016 04:49:09 -0400 Received: from mout.web.de ([212.227.15.3]:59995 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752162AbcHUItH (ORCPT ); Sun, 21 Aug 2016 04:49:07 -0400 Received: from [192.168.1.3] ([77.181.85.179]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0MGifp-1bNu1m1Nmz-00DUdK; Sun, 21 Aug 2016 10:48:55 +0200 Subject: [PATCH] megaraid_sas: Use memdup_user() rather than duplicating its implementation References: <566ABCD9.1060404@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall To: linux-scsi@vger.kernel.org, megaraidlinux.pdl@avagotech.com, "James E. J. Bottomley" , Kashyap Desai , "Martin K. Petersen" , Sumit Saxena , Uday Lingala From: SF Markus Elfring Message-ID: <606e0b0c-370f-cff5-607b-0c8ae480e9c1@users.sourceforge.net> Date: Sun, 21 Aug 2016 10:48:48 +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: <566ABCD9.1060404@users.sourceforge.net> X-Provags-ID: V03:K0:/XTQj2XTa3z9yUCEMNBR6WjnIdNjenV6ueum9ATJSxhhx9ZuKAm oz/ChhZ3v7ptQum5+EwnK1UwlMh6UIiEtgtEQNlnGA0bKUBcAU1q4u+TKeTON4YDbHJyd4n CSPGgxjS2jo9wMt3VxPx+j/CCu2U8EQQneLgyYW/ssHJkCCUYqqfzwMhXwlMJ5xaWwyG//g vddmAO4IgW41HCD90Akew== X-UI-Out-Filterresults: notjunk:1; V01:K0:YtC+G39XdpU=:JDgz8ozfHuQM2Jise4DvKV L1lyRCiOfpTn7mJj2YTTzog+IYfFWbHsfWFE7zWwTHSjP7FiDxZnVB8AkeDQZvm96ws6eXTn6 /+B7KsBRys+fT/4soqlszXGtiMiFjBCRwpKnbV91ucr+MsWNxmvHx5MMT7Go980mCSP9o8nuw 0aqRurB9ZdtFw/bJcBYv/CPK7Q7u/0NgsWnZYX9L5fn8/SKBSzMCdg2dyuUGx58Pn1TrCuZcB as0BFqei/t3wlTWpLSSyIZkhwQVhaDtku5WNy2c5PEFVMggQqpjxPAj2citKufN6CduOOQ9pS 5r2RlOCWz3DKRFhzlOHyF5Oba0iyAc4/GkIMMijH5pH/hom1K2WJ6n3TCgJfieZSPsE23du1c uZlxOPQTY9OCeLVPZoUMBKm0nAsSXgRp2srOO9PBPGldzurprDR6Kdc9CJuvAf/y2Z6pp4klU J8d3rwZrEA2+xgMiuAgohgA0DxJrdKfQXF0DDF8G4CcI196u+6g3qJUOnShmuAF/aKnE++X8K 5a7r+9w/PSgA2Omj5KQpbe+IJSD9iueImqQcVMDhMCbc40x11I2DrHP03CkOu3g2ylecsv7w0 6q6alcKW1u5yK9PhCTPxJJtoYwLtYSNTKaDgelVqMFUZ+ZIfNy3q6b+FGIVhci+aK6sqQBidf MXyw+H41atAvZSNRE23sL2U2K7NBCmAN4ix/WlTEsZnhFBzybcwPBkkFWt50KbHwe44JH/s6e bHjVW5Zuy8TcBHubuAz4mPxApPiglrLpFI2HWqtRpugNUXy2hkPM1e6PynA8ZcijWw5m41fdi cN/k5FW Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 21 Aug 2016 10:39:04 +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/scsi/megaraid/megaraid_sas_base.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c index c1ed25a..9a2fe4e 100644 --- a/drivers/scsi/megaraid/megaraid_sas_base.c +++ b/drivers/scsi/megaraid/megaraid_sas_base.c @@ -6711,14 +6711,9 @@ static int megasas_mgmt_ioctl_fw(struct file *file, unsigned long arg) unsigned long flags; u32 wait_time = MEGASAS_RESET_WAIT_TIME; - ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); - if (!ioc) - return -ENOMEM; - - if (copy_from_user(ioc, user_ioc, sizeof(*ioc))) { - error = -EFAULT; - goto out_kfree_ioc; - } + ioc = memdup_user(user_ioc, sizeof(*ioc)); + if (IS_ERR(ioc)) + return PTR_ERR(ioc); instance = megasas_lookup_instance(ioc->host_no); if (!instance) {