* [PATCH] block: floppy: Replace kmalloc() + copy_from_user() with memdup_user()
@ 2025-09-08 20:10 Thorsten Blum
2025-09-09 15:11 ` Jens Axboe
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2025-09-08 20:10 UTC (permalink / raw)
To: Denis Efremov, Jens Axboe; +Cc: Thorsten Blum, linux-block, linux-kernel
Replace kmalloc() followed by copy_from_user() with memdup_user() to
improve and simplify raw_cmd_copyin().
No functional changes intended.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
drivers/block/floppy.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 24be0c2c4075..b33c6543ddf2 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3092,16 +3092,13 @@ static int raw_cmd_copyin(int cmd, void __user *param,
*rcmd = NULL;
loop:
- ptr = kmalloc(sizeof(struct floppy_raw_cmd), GFP_KERNEL);
- if (!ptr)
- return -ENOMEM;
+ ptr = memdup_user(param, sizeof(*ptr));
+ if (IS_ERR(ptr))
+ return PTR_ERR(ptr);
*rcmd = ptr;
- ret = copy_from_user(ptr, param, sizeof(*ptr));
ptr->next = NULL;
ptr->buffer_length = 0;
ptr->kernel_data = NULL;
- if (ret)
- return -EFAULT;
param += sizeof(struct floppy_raw_cmd);
if (ptr->cmd_count > FD_RAW_CMD_FULLSIZE)
return -EINVAL;
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-09 15:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-08 20:10 [PATCH] block: floppy: Replace kmalloc() + copy_from_user() with memdup_user() Thorsten Blum
2025-09-09 15:11 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox