Skip to content

Commit ac01fc4

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

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

drivers/scsi/hpsa.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6402,18 +6402,14 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h,
64026402
return -EINVAL;
64036403
}
64046404
if (iocommand->buf_size > 0) {
6405-
buff = kmalloc(iocommand->buf_size, GFP_KERNEL);
6406-
if (buff == NULL)
6407-
return -ENOMEM;
64086405
if (iocommand->Request.Type.Direction & XFER_WRITE) {
6409-
/* Copy the data into the buffer we created */
6410-
if (copy_from_user(buff, iocommand->buf,
6411-
iocommand->buf_size)) {
6412-
rc = -EFAULT;
6413-
goto out_kfree;
6414-
}
6406+
buff = memdup_user(iocommand->buf, iocommand->buf_size);
6407+
if (IS_ERR(buff))
6408+
return PTR_ERR(buff);
64156409
} else {
6416-
memset(buff, 0, iocommand->buf_size);
6410+
buff = kzalloc(iocommand->buf_size, GFP_KERNEL);
6411+
if (!buff)
6412+
return -ENOMEM;
64176413
}
64186414
}
64196415
c = cmd_alloc(h);
@@ -6473,7 +6469,6 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h,
64736469
}
64746470
out:
64756471
cmd_free(h, c);
6476-
out_kfree:
64776472
kfree(buff);
64786473
return rc;
64796474
}

0 commit comments

Comments
 (0)