mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mmc/core/block: Use memdup_user() rather than duplicating its implementation
@ 2018-03-05 12:08 SF Markus Elfring
  2018-03-15 10:23 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2018-03-05 12:08 UTC (permalink / raw)
  To: linux-mmc, Adrian Hunter, Linus Walleij, Shawn Lin, Ulf Hansson
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mmc/core/block: Use memdup_user() rather than duplicating its implementation
  2018-03-05 12:08 [PATCH] mmc/core/block: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
@ 2018-03-15 10:23 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2018-03-15 10:23 UTC (permalink / raw)
  To: SF Markus Elfring
  Cc: linux-mmc, Adrian Hunter, Linus Walleij, Shawn Lin, LKML,
	kernel-janitors

On 5 March 2018 at 13:08, SF Markus Elfring
<elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>

Thanks, applied for next!

Kind regards
Uffe

> ---
>  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
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-03-15 10:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-05 12:08 [PATCH] mmc/core/block: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
2018-03-15 10:23 ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome