* [PATCH RESEND] scsi: hpsa: Replace kmalloc + copy_from_user with memdup_user
@ 2025-09-23 17:15 Thorsten Blum
2025-09-23 19:40 ` Don.Brace
2025-09-25 1:41 ` Martin K. Petersen
0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-09-23 17:15 UTC (permalink / raw)
To: Don Brace, James E.J. Bottomley, Martin K. Petersen
Cc: Thorsten Blum, storagedev, linux-scsi, linux-kernel
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>
---
drivers/scsi/hpsa.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index c73a71ac3c29..55448238d8ed 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -6407,18 +6407,14 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h,
return -EINVAL;
}
if (iocommand->buf_size > 0) {
- buff = kmalloc(iocommand->buf_size, GFP_KERNEL);
- if (buff == NULL)
- return -ENOMEM;
if (iocommand->Request.Type.Direction & XFER_WRITE) {
- /* Copy the data into the buffer we created */
- if (copy_from_user(buff, iocommand->buf,
- iocommand->buf_size)) {
- rc = -EFAULT;
- goto out_kfree;
- }
+ buff = memdup_user(iocommand->buf, iocommand->buf_size);
+ if (IS_ERR(buff))
+ return PTR_ERR(buff);
} else {
- memset(buff, 0, iocommand->buf_size);
+ buff = kzalloc(iocommand->buf_size, GFP_KERNEL);
+ if (!buff)
+ return -ENOMEM;
}
}
c = cmd_alloc(h);
@@ -6478,7 +6474,6 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h,
}
out:
cmd_free(h, c);
-out_kfree:
kfree(buff);
return rc;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND] scsi: hpsa: Replace kmalloc + copy_from_user with memdup_user
2025-09-23 17:15 [PATCH RESEND] scsi: hpsa: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
@ 2025-09-23 19:40 ` Don.Brace
2025-09-23 21:15 ` Thorsten Blum
2025-09-25 1:41 ` Martin K. Petersen
1 sibling, 1 reply; 4+ messages in thread
From: Don.Brace @ 2025-09-23 19:40 UTC (permalink / raw)
To: thorsten.blum, James.Bottomley, martin.petersen
Cc: storagedev, linux-scsi, linux-kernel
________________________________________
From: Thorsten Blum <thorsten.blum@linux.dev>
Sent: Tuesday, September 23, 2025 12:15 PM
To: Don Brace - C33706 <Don.Brace@microchip.com>; James E.J. Bottomley <James.Bottomley@HansenPartnership.com>; Martin K. Petersen <martin.petersen@oracle.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>; storagedev <storagedev@microchip.com>; linux-scsi@vger.kernel.org <linux-scsi@vger.kernel.org>; linux-kernel@vger.kernel.org <linux-kernel@vger.kernel.org>
Subject: [PATCH RESEND] scsi: hpsa: Replace kmalloc + copy_from_user with memdup_user
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
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>
Thanks for your patch.
We do not normally make changes to this driver as it is in maintenance mode.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND] scsi: hpsa: Replace kmalloc + copy_from_user with memdup_user
2025-09-23 19:40 ` Don.Brace
@ 2025-09-23 21:15 ` Thorsten Blum
0 siblings, 0 replies; 4+ messages in thread
From: Thorsten Blum @ 2025-09-23 21:15 UTC (permalink / raw)
To: Don.Brace
Cc: <James.Bottomley@hansenpartnership.com>, martin.petersen,
storagedev, linux-scsi, linux-kernel
Hi Don,
On 23. Sep 2025, at 21:40, Don.Brace@microchip.com wrote:
> ...
> Thanks for your patch.
>
> We do not normally make changes to this driver as it is in maintenance mode.
Is there a general way to check if a driver is in maintenance mode?
Did you get a chance to look at my other patch [1] yet, which fixes a
potential memory leak in this driver? That's probably more important
than the refactorings.
Thanks,
Thorsten
[1] https://lore.kernel.org/lkml/20250919092637.721325-1-thorsten.blum@linux.dev/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND] scsi: hpsa: Replace kmalloc + copy_from_user with memdup_user
2025-09-23 17:15 [PATCH RESEND] scsi: hpsa: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
2025-09-23 19:40 ` Don.Brace
@ 2025-09-25 1:41 ` Martin K. Petersen
1 sibling, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2025-09-25 1:41 UTC (permalink / raw)
To: Thorsten Blum
Cc: Don Brace, James E.J. Bottomley, Martin K. Petersen, storagedev,
linux-scsi, linux-kernel
Thorsten,
> 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.
Applied to 6.18/scsi-staging, thanks!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-25 1:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-23 17:15 [PATCH RESEND] scsi: hpsa: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
2025-09-23 19:40 ` Don.Brace
2025-09-23 21:15 ` Thorsten Blum
2025-09-25 1:41 ` Martin K. Petersen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox