Skip to content

Commit 8791b07

Browse files
tobluxmartinkpetersen
authored andcommitted
scsi: scsi_debug: Replace kzalloc() + copy_from_user() with memdup_user_nul()
Replace kzalloc() followed by copy_from_user() with memdup_user_nul() to improve and simplify sdebug_error_write(). No functional changes intended. Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 5cffc67 commit 8791b07

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

drivers/scsi/scsi_debug.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,14 +1155,9 @@ static ssize_t sdebug_error_write(struct file *file, const char __user *ubuf,
11551155
struct sdebug_err_inject *inject;
11561156
struct scsi_device *sdev = (struct scsi_device *)file->f_inode->i_private;
11571157

1158-
buf = kzalloc(count + 1, GFP_KERNEL);
1159-
if (!buf)
1160-
return -ENOMEM;
1161-
1162-
if (copy_from_user(buf, ubuf, count)) {
1163-
kfree(buf);
1164-
return -EFAULT;
1165-
}
1158+
buf = memdup_user_nul(ubuf, count);
1159+
if (IS_ERR(buf))
1160+
return PTR_ERR(buf);
11661161

11671162
if (buf[0] == '-')
11681163
return sdebug_err_remove(sdev, buf, count);

0 commit comments

Comments
 (0)