From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-mmc@vger.kernel.org,
Adrian Hunter <adrian.hunter@intel.com>,
Grant Grundler <grundler@chromium.org>, Jens Axboe <axboe@fb.com>,
Jon Hunter <jonathanh@nvidia.com>,
Mike Christie <mchristi@redhat.com>,
Shawn Lin <shawn.lin@rock-chips.com>,
Ulf Hansson <ulf.hansson@linaro.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org,
Julia Lawall <julia.lawall@lip6.fr>
Subject: [PATCH 1/2] mmc-block: Use memdup_user() rather than duplicating its implementation
Date: Fri, 19 Aug 2016 23:10:07 +0200 [thread overview]
Message-ID: <10db7d07-0cee-041f-8755-de412a12bc81@users.sourceforge.net> (raw)
In-Reply-To: <68870228-c6a0-5de9-daee-2522a1303857@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Fri, 19 Aug 2016 22:46:38 +0200
* Reuse existing functionality from memdup_user() instead of keeping
duplicate source code.
This issue was detected by using the Coccinelle software.
* Delete the integer variable "err" then because the pointer
variable "idata" should be sufficient to handle return values alone
in this function.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/mmc/card/block.c | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 48a5dd7..6ce9492 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -337,22 +337,21 @@ static struct mmc_blk_ioc_data *mmc_blk_ioctl_copy_from_user(
struct mmc_ioc_cmd __user *user)
{
struct mmc_blk_ioc_data *idata;
- int err;
idata = kmalloc(sizeof(*idata), GFP_KERNEL);
if (!idata) {
- err = -ENOMEM;
+ idata = ERR_PTR(-ENOMEM);
goto out;
}
if (copy_from_user(&idata->ic, user, sizeof(idata->ic))) {
- err = -EFAULT;
+ idata = ERR_PTR(-EFAULT);
goto idata_err;
}
idata->buf_bytes = (u64) idata->ic.blksz * idata->ic.blocks;
if (idata->buf_bytes > MMC_IOC_MAX_BYTES) {
- err = -EOVERFLOW;
+ idata = ERR_PTR(-EOVERFLOW);
goto idata_err;
}
@@ -361,26 +360,19 @@ 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)) {
+ idata = (void *) 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:
- return ERR_PTR(err);
+ return idata;
}
static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr,
--
2.9.3
next prev parent reply other threads:[~2016-08-19 21:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <566ABCD9.1060404@users.sourceforge.net>
2015-12-29 19:50 ` [PATCH] mmc-core: One check less in mmc_select_hs200() after error detection SF Markus Elfring
2016-01-12 15:07 ` Ulf Hansson
2015-12-29 20:57 ` [PATCH 0/2] mmc-host: Fine-tuning for one function SF Markus Elfring
2015-12-29 21:00 ` [PATCH 1/2] mmc-sdricoh_cs: Delete unnecessary variable initialisations in sdricoh_init_mmc() SF Markus Elfring
2016-02-21 9:11 ` Sascha Sommer
2015-12-29 21:02 ` [PATCH 2/2] mmc-sdricoh_cs: Less checks in sdricoh_init_mmc() after, error detection SF Markus Elfring
2016-02-21 9:15 ` Sascha Sommer
2016-01-27 14:15 ` [PATCH 0/2] mmc-host: Fine-tuning for one function Ulf Hansson
2016-08-19 21:07 ` [PATCH 0/2] mmc-block: Fine-tuning for mmc_blk_ioctl_copy_from_user() SF Markus Elfring
2016-08-19 21:10 ` SF Markus Elfring [this message]
2016-08-20 9:25 ` [PATCH 1/2] mmc-block: Use memdup_user() rather than duplicating its implementation walter harms
2016-08-19 21:12 ` [PATCH 2/2] mmc-block: Rename jump labels in mmc_blk_ioctl_copy_from_user() SF Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10db7d07-0cee-041f-8755-de412a12bc81@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=adrian.hunter@intel.com \
--cc=axboe@fb.com \
--cc=grundler@chromium.org \
--cc=jonathanh@nvidia.com \
--cc=julia.lawall@lip6.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=mchristi@redhat.com \
--cc=shawn.lin@rock-chips.com \
--cc=ulf.hansson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).