mirror of https://github.com/torvalds/linux.git
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 <thorsten.blum@linux.dev> Acked-by: Don Brace <don.brace@microchip.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
parent
b81296591c
commit
ac01fc418f
|
|
@ -6402,18 +6402,14 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
if (iocommand->buf_size > 0) {
|
if (iocommand->buf_size > 0) {
|
||||||
buff = kmalloc(iocommand->buf_size, GFP_KERNEL);
|
|
||||||
if (buff == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
if (iocommand->Request.Type.Direction & XFER_WRITE) {
|
if (iocommand->Request.Type.Direction & XFER_WRITE) {
|
||||||
/* Copy the data into the buffer we created */
|
buff = memdup_user(iocommand->buf, iocommand->buf_size);
|
||||||
if (copy_from_user(buff, iocommand->buf,
|
if (IS_ERR(buff))
|
||||||
iocommand->buf_size)) {
|
return PTR_ERR(buff);
|
||||||
rc = -EFAULT;
|
|
||||||
goto out_kfree;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
memset(buff, 0, iocommand->buf_size);
|
buff = kzalloc(iocommand->buf_size, GFP_KERNEL);
|
||||||
|
if (!buff)
|
||||||
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c = cmd_alloc(h);
|
c = cmd_alloc(h);
|
||||||
|
|
@ -6473,7 +6469,6 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h,
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
cmd_free(h, c);
|
cmd_free(h, c);
|
||||||
out_kfree:
|
|
||||||
kfree(buff);
|
kfree(buff);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue