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

From: mdshahid03

Date: Sun Jul 05 2026 - 01:17:34 EST


From: Mohammad Shahid <mdshahid03@xxxxxxxxx>

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.

Signed-off-by: Mohammad Shahid <mdshahid03@xxxxxxxxx>
---
drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c b/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
index e6ea9422d6f2..addafd60bbe6 100644
--- a/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
+++ b/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
@@ -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);
--
2.43.0