Skip to contentSkip to conversation

firmware: tegra: switch over to memdup_user()

PATCH In review Qing Wang 2 participants 3 messages Oct 18, 2021 – Oct 21, 2021 1 message not in the archive Tegra architecture support

lore
Share & tools
lore

Qing Wang

author
#0 lore raw

PATCH 1/1 firmware: tegra: switch over to memdup_user()

This patch fixes the following Coccinelle warning:

drivers/firmware/tegra/bpmp-debugfs.c:379: WARNING opportunity for memdup_user

Use memdup_user rather than duplicating its implementation This is a little bit restricted to reduce false positives

---
 drivers/firmware/tegra/bpmp-debugfs.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)
drivers/firmware/tegra/bpmp-debugfs.c +3 -10
index 6d66fe0..0435709
@@ -376,18 +376,11 @@ static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,
 	if (!filename)
 		return -ENOENT;
 
-	databuf = kmalloc(count, GFP_KERNEL);
-	if (!databuf)
-		return -ENOMEM;
-
-	if (copy_from_user(databuf, buf, count)) {
-		err = -EFAULT;
-		goto free_ret;
-	}
+	databuf = memdup_user(buf, count);
+	if (IS_ERR(databuf))
+		return ERR_PTR(PTR_ERR(databuf));
 
 	err = mrq_debug_write(bpmp, filename, databuf, count);
-
-free_ret:
 	kfree(databuf);
 
 	return err ?: count;
Signature · 1 line
2.7.4
#1 lore raw

On Mon, Oct 18, 2021 at 12:59:40AM -0700, Qing Wang wrote:
[...]

Quoted 7 lines
drivers/firmware/tegra/bpmp-debugfs.c +0 -1
@@ -376,18 +376,11 @@ static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,
 	if (!filename)
 		return -ENOENT;
 
-	databuf = kmalloc(count, GFP_KERNEL);

drivers/firmware/tegra/bpmp-debugfs.c static ssize_t bpmp_debug_store(struct file *file, const char __user *buf, · line 381

Quoted 10 lines
drivers/firmware/tegra/bpmp-debugfs.c +3 -7
-	if (!databuf)
-		return -ENOMEM;
-
-	if (copy_from_user(databuf, buf, count)) {
-		err = -EFAULT;
-		goto free_ret;
-	}
+	databuf = memdup_user(buf, count);
+	if (IS_ERR(databuf))
+		return ERR_PTR(PTR_ERR(databuf));

ERR_PTR() is too much here.

Best Regards
Michał Mirosław

A message that is not in the archive (sent off-list or not yet received): AJsAPABcEiDeZ4ZDMvu*[email protected]

author
#3 lore raw
Quoted 21 lines
Quoted 10 lines
drivers/firmware/tegra/bpmp-debugfs.c +0 -0
@@ -376,18 +376,11 @@ static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,
         if (!filename)
                 return -ENOENT;


-     databuf = kmalloc(count, GFP_KERNEL);
-     if (!databuf)
-             return -ENOMEM;

Quoted 8 lines

-
-     if (copy_from_user(databuf, buf, count)) {
-             err = -EFAULT;
-             goto free_ret;
-     }
+     databuf = memdup_user(buf, count);
+     if (IS_ERR(databuf))
+             return ERR_PTR(PTR_ERR(databuf));

ERR_PTR() is too much here.

Quoted 2 lines

Best Regards
Michał Mirosław

Sorry about that, I have resent the patch, Please ignore this version.

Thanks,
Qing