* [PATCH] scsi: scsi_debug: Replace kzalloc() + copy_from_user() with memdup_user_nul()
@ 2025-09-05 10:31 Thorsten Blum
2025-09-05 16:41 ` Bart Van Assche
2025-09-10 2:32 ` Martin K. Petersen
0 siblings, 2 replies; 3+ messages in thread
From: Thorsten Blum @ 2025-09-05 10:31 UTC (permalink / raw)
To: James E.J. Bottomley, Martin K. Petersen
Cc: Thorsten Blum, linux-scsi, linux-kernel
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>
---
drivers/scsi/scsi_debug.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 353cb60e1abe..83d49c58b11d 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -1155,14 +1155,9 @@ static ssize_t sdebug_error_write(struct file *file, const char __user *ubuf,
struct sdebug_err_inject *inject;
struct scsi_device *sdev = (struct scsi_device *)file->f_inode->i_private;
- buf = kzalloc(count + 1, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- if (copy_from_user(buf, ubuf, count)) {
- kfree(buf);
- return -EFAULT;
- }
+ buf = memdup_user_nul(ubuf, count);
+ if (IS_ERR(buf))
+ return PTR_ERR(buf);
if (buf[0] == '-')
return sdebug_err_remove(sdev, buf, count);
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: scsi_debug: Replace kzalloc() + copy_from_user() with memdup_user_nul()
2025-09-05 10:31 [PATCH] scsi: scsi_debug: Replace kzalloc() + copy_from_user() with memdup_user_nul() Thorsten Blum
@ 2025-09-05 16:41 ` Bart Van Assche
2025-09-10 2:32 ` Martin K. Petersen
1 sibling, 0 replies; 3+ messages in thread
From: Bart Van Assche @ 2025-09-05 16:41 UTC (permalink / raw)
To: Thorsten Blum, James E.J. Bottomley, Martin K. Petersen
Cc: linux-scsi, linux-kernel
On 9/5/25 3:31 AM, Thorsten Blum wrote:
> Replace kzalloc() followed by copy_from_user() with memdup_user_nul() to
> improve and simplify sdebug_error_write().
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] scsi: scsi_debug: Replace kzalloc() + copy_from_user() with memdup_user_nul()
2025-09-05 10:31 [PATCH] scsi: scsi_debug: Replace kzalloc() + copy_from_user() with memdup_user_nul() Thorsten Blum
2025-09-05 16:41 ` Bart Van Assche
@ 2025-09-10 2:32 ` Martin K. Petersen
1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2025-09-10 2:32 UTC (permalink / raw)
To: Thorsten Blum
Cc: James E.J. Bottomley, Martin K. Petersen, linux-scsi,
linux-kernel
Thorsten,
> Replace kzalloc() followed by copy_from_user() with memdup_user_nul()
> to improve and simplify sdebug_error_write().
Applied to 6.18/scsi-staging, thanks!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-10 2:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-05 10:31 [PATCH] scsi: scsi_debug: Replace kzalloc() + copy_from_user() with memdup_user_nul() Thorsten Blum
2025-09-05 16:41 ` Bart Van Assche
2025-09-10 2:32 ` 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