[PATCH] floppy: use memdup_user

From: Geliang Tang
Date: Fri Apr 28 2017 - 21:46:44 EST


Use memdup_user() helper instead of open-coding to simplify the code.

Signed-off-by: Geliang Tang <geliangtang@xxxxxxxxx>
---
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 60d4c76..167426c 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3121,16 +3121,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 > 33)
/* the command may now also take up the space
--
2.9.3