Received: by 10.223.185.116 with SMTP id b49csp2625761wrg; Mon, 5 Mar 2018 06:13:35 -0800 (PST) X-Google-Smtp-Source: AG47ELvfuZyJZqSIKf7UoEZWD+C3hZB56duzs1wG1CXIzUxHaJMAjszNwkxnYUFczrUlcrfrEuA3 X-Received: by 10.99.127.90 with SMTP id p26mr12396152pgn.268.1520259215038; Mon, 05 Mar 2018 06:13:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520259214; cv=none; d=google.com; s=arc-20160816; b=ddfl/8l1OeBZFY5V5jfQuADUlCBZoeRuN7+70F7X/8eZ/OglW6oGBLXHScpXF1hpaG Mb+rImSv45FgrlWuw8WYkpxY4T6Mwy3G1EtuDzuwrsZu4giW8JfJ5gudon+ioRWdg9Rx wHLLN8YTE/ARds9BjB4R7HYUBUWlekL3LdrdfXJLEoFc6P7JdDTP2mKmsvW8I7K8JSmu FcHlpQPUnK7G9bpQfsjx0l+oAnqFQP4sbTwr4KrsHXfbv7ik4ZcfH3T4y7lqFn8TpFVd 7QMSBaQk1hc9eZxJ1M3G3uE962XaSn/aZaZwZJfYjaIBzOzTDgAvO7FSJMBxNQZ2iBqP 5kpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:subject :from:cc:to:arc-authentication-results; bh=J9xk4ERVTlSt4+ebLueSoLzcmx1Njl+1h6wJ8+c5V1Y=; b=tIljOD0tlveVsHAL1qjMS46Rev0UpEOn67Qm+UNxv144lGXnaQgSpdb8TxREo0cp5H OceriOQWa5GXlV2ccCrjeBtPQOTo9HqH0X+wtu8RtzMHODlj5UNwHuG7VFnOctpVVWzo eai99604MBYL8Fr7Db3mu5BZeIz/w7fFmcEjZjWHKgg4s4wbn86XBJmnPaKNNCzSXnWS 0IAqKROAqBYPNBHysRaBReJ8rnrn8PxxTp5Oy9nC7wqclJ9yDzv2mAqpwSnzc0AK/Gxe liAJNdrzQ35DmUJhd5Q4kX1OYwDVHjOMr2mMxXA7kIjdZI26sfPw3BKgsJRy2pqp8JnG EdeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=sourceforge.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r20si8408807pgu.423.2018.03.05.06.13.20; Mon, 05 Mar 2018 06:13:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=sourceforge.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934532AbeCEMIU (ORCPT + 99 others); Mon, 5 Mar 2018 07:08:20 -0500 Received: from mout.web.de ([217.72.192.78]:59241 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932911AbeCEMIS (ORCPT ); Mon, 5 Mar 2018 07:08:18 -0500 Received: from [192.168.1.2] ([92.228.188.109]) by smtp.web.de (mrweb101 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LgYG1-1eMjkA3j8f-00nzPB; Mon, 05 Mar 2018 13:08:08 +0100 To: linux-mmc@vger.kernel.org, Adrian Hunter , Linus Walleij , Shawn Lin , Ulf Hansson Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] mmc/core/block: Use memdup_user() rather than duplicating its implementation Message-ID: <4eca7388-cb2d-31e0-b64d-afb30818f53e@users.sourceforge.net> Date: Mon, 5 Mar 2018 13:08:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:bfFw8Y5PHWdrOaMOGNVyI1H9ew94icNpI4MGpkuWEKyCXUWOnUB awKFFgK0CsY4zTVJq0YS0x4b/TabIuVD95vpIS0iuexhOVLjJHZ7vY94+aowMfWnYccJu+x /cVQo4uvWdNYPa7m7vUXoT+Nn/sGekvMWYdSKMw54NPbP1S9E2YfgZnIM9bLhde8SAc2xz0 U93Am7AozraH2CiulTbvw== X-UI-Out-Filterresults: notjunk:1;V01:K0:/lMMKBuLYLQ=:wFOGqMEGBSIZZtZYE3GMXX aqhdWqvmekqeT0NtuKpwI1Zb6FSAuB6OKebKmbTi1AkJGUbW81aiBIOqCkNMMgzz7u6gnFVPm C+y6SNhlsmZDvpHmwGS8fyolFQSR266gFLfjD1DavlTtW3+4Hnk6pK4glo8+/sLkTJlN2DDJl OBuaAgyIBzFYrgwYvOao6ukSfet0Aw0qnshU/6c3tS1pzefs6OWY2SIskPJgaJYtCz6eayUhL y/nVzYP4xXHLHtBlfK4/NuPBVuNXvG2vE+I1PFmR93sMZ1xCLXVJ4FhaIvTBaH+6gSmRJpqDP OmWkfSFX9+tRlG/lQBRciF+EEx8MwmXmuPBvMB8+gQaHr6F3UH5Z5PGng/n/203sBet5oy5XD 6gNUM4bmLuDQ2HQzRw9oZ+gAtvnefm51JEE02xr8GU3HOlgNZok9jop/Rf9qREhz9aXXROVM9 x2aDDRWd7+tRuHsAkAUi3dOMfPp9wX3EC+AqDOELGC6vYzRgPPDoxWaN/e8/UuzBs9SDMekql 3oW0BevSILEH+HZCRiu6bMqpj3yugROHev6Uz+lM37ou00dnWvd7u/hh34MapueXE6/M+zWg7 BTie5IkkSHOe3yIxpfSnPMvS6NLWYdpyaeKPF7aLoIoXILrt1wCX2z3p821F3xAzeQh7BjzBv 75bPjyZUGJWQIRt8zVKythW7tyRvqsxjsKXoY+CSIUYG8VM/xGJUiYF53u/FxwxV3NLNxIKrp 3wP+ooJ2zLWstW1h9xiRt9fgwicxBhd4i+W/VgdHZlt0ljU+OTVHGgmk79LwXMEtHckRBu2dp 2eOLvKyopj5i6Ea/0ESGcwulnVROoSuPUCpJad9HasDqEDfsIk= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Markus Elfring Date: Mon, 5 Mar 2018 11:33:21 +0100 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/mmc/core/block.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 20135a5de748..4b09c7380e70 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -375,22 +375,15 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user( return idata; } - idata->buf = kmalloc(idata->buf_bytes, GFP_KERNEL); - if (!idata->buf) { - err = -ENOMEM; + idata->buf = memdup_user((void __user *)(unsigned long) + idata->ic.data_ptr, idata->buf_bytes); + if (IS_ERR(idata->buf)) { + err = PTR_ERR(idata->buf); goto idata_err; } - if (copy_from_user(idata->buf, (void __user *)(unsigned long) - idata->ic.data_ptr, idata->buf_bytes)) { - err = -EFAULT; - goto copy_err; - } - return idata; -copy_err: - kfree(idata->buf); idata_err: kfree(idata); out: -- 2.16.2