Skip to contentSkip to conversation

gpib: lpvo_usb_gpib: use memdup_user() instead of kmalloc() and copy_from_user()

PATCH New [email protected] 1 participant 1 message Jul 5 GPIB drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpib: lpvo_usb_gpib: use memdup_user() instead of kmalloc() and copy_from_user()

From: Mohammad Shahid <[email protected]>

Use memdup_user() to replace the open-coded kmalloc() and copy_from_user() sequence.

This simplifies the code while preserving the existing behavior.

This issue was reported by memdup_user.cocci.

---
 drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c +3 -8
index e6ea9422d6f2..addafd60bbe6 100644
@@ -1811,14 +1811,9 @@ static ssize_t lpvo_write(struct file *file, const char __user *user_buffer,
 
 	dev = file->private_data;
 
-	buf = kmalloc(count, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
-
-	if (copy_from_user(buf, user_buffer, count)) {
-		kfree(buf);
-		return -EFAULT;
-	}
+	buf = memdup_user(user_buffer, count);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
 
 	rv = lpvo_do_write(dev, buf, count);
 	kfree(buf);
Signature · 1 line
2.43.0