Commit 6f0b826d authored by Markus Elfring's avatar Markus Elfring Committed by David S. Miller

mlx5/core: Use memdup_user() rather than duplicating its implementation

* Reuse existing functionality from memdup_user() instead of keeping
  duplicate source code.

  This issue was detected by using the Coccinelle software.

* Return directly if this copy operation failed.
Signed-off-by: default avatarMarkus Elfring <elfring@users.sourceforge.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b9a24bb7
...@@ -1015,7 +1015,6 @@ static ssize_t data_write(struct file *filp, const char __user *buf, ...@@ -1015,7 +1015,6 @@ static ssize_t data_write(struct file *filp, const char __user *buf,
struct mlx5_core_dev *dev = filp->private_data; struct mlx5_core_dev *dev = filp->private_data;
struct mlx5_cmd_debug *dbg = &dev->cmd.dbg; struct mlx5_cmd_debug *dbg = &dev->cmd.dbg;
void *ptr; void *ptr;
int err;
if (*pos != 0) if (*pos != 0)
return -EINVAL; return -EINVAL;
...@@ -1023,25 +1022,15 @@ static ssize_t data_write(struct file *filp, const char __user *buf, ...@@ -1023,25 +1022,15 @@ static ssize_t data_write(struct file *filp, const char __user *buf,
kfree(dbg->in_msg); kfree(dbg->in_msg);
dbg->in_msg = NULL; dbg->in_msg = NULL;
dbg->inlen = 0; dbg->inlen = 0;
ptr = memdup_user(buf, count);
ptr = kzalloc(count, GFP_KERNEL); if (IS_ERR(ptr))
if (!ptr) return PTR_ERR(ptr);
return -ENOMEM;
if (copy_from_user(ptr, buf, count)) {
err = -EFAULT;
goto out;
}
dbg->in_msg = ptr; dbg->in_msg = ptr;
dbg->inlen = count; dbg->inlen = count;
*pos = count; *pos = count;
return count; return count;
out:
kfree(ptr);
return err;
} }
static ssize_t data_read(struct file *filp, char __user *buf, size_t count, static ssize_t data_read(struct file *filp, char __user *buf, size_t count,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment