Skip to content

Commit 0ac3c90

Browse files
tobluxmartinkpetersen
authored andcommitted
scsi: smartpqi: Replace kmalloc() + copy_from_user() with memdup_user()
Replace kmalloc() followed by copy_from_user() with memdup_user() to simplify and improve pqi_passthru_ioctl(). Since memdup_user() already allocates memory, use kzalloc() in the else branch instead of manually zeroing 'kernel_buffer' using memset(0). Return early if an error occurs. No functional changes intended. Signed-off-by: Thorsten Blum <[email protected]> Acked-by: Don Brace <[email protected]> Message-Id: <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent ac01fc4 commit 0ac3c90

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

drivers/scsi/smartpqi/smartpqi_init.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/reboot.h>
2121
#include <linux/cciss_ioctl.h>
2222
#include <linux/crash_dump.h>
23+
#include <linux/string.h>
2324
#include <scsi/scsi_host.h>
2425
#include <scsi/scsi_cmnd.h>
2526
#include <scsi/scsi_device.h>
@@ -6774,17 +6775,15 @@ static int pqi_passthru_ioctl(struct pqi_ctrl_info *ctrl_info, void __user *arg)
67746775
}
67756776

67766777
if (iocommand.buf_size > 0) {
6777-
kernel_buffer = kmalloc(iocommand.buf_size, GFP_KERNEL);
6778-
if (!kernel_buffer)
6779-
return -ENOMEM;
67806778
if (iocommand.Request.Type.Direction & XFER_WRITE) {
6781-
if (copy_from_user(kernel_buffer, iocommand.buf,
6782-
iocommand.buf_size)) {
6783-
rc = -EFAULT;
6784-
goto out;
6785-
}
6779+
kernel_buffer = memdup_user(iocommand.buf,
6780+
iocommand.buf_size);
6781+
if (IS_ERR(kernel_buffer))
6782+
return PTR_ERR(kernel_buffer);
67866783
} else {
6787-
memset(kernel_buffer, 0, iocommand.buf_size);
6784+
kernel_buffer = kzalloc(iocommand.buf_size, GFP_KERNEL);
6785+
if (!kernel_buffer)
6786+
return -ENOMEM;
67886787
}
67896788
}
67906789

0 commit comments

Comments
 (0)