Skip to contentSkip to conversation

mmc/core/block: Use memdup_user() rather than duplicating its implementation

PATCH Applied SF Markus Elfring 2 participants 2 messages Mar 5, 2018 – Mar 15, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc/core/block: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
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.

---
 drivers/mmc/core/block.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/mmc/core/block.c +4 -11
index 20135a5de748..4b09c7380e70 100644
@@ -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:
Signature · 1 line
2.16.2
Applied
#1 lore raw
Quoted 9 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
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.

Thanks, applied for next!

Kind regards
Uffe

Quoted 42 lines
---
 drivers/mmc/core/block.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/mmc/core/block.c +4 -12
index 20135a5de748..4b09c7380e70 100644
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html