Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1466805
| From | walter harms <wharms@bfs.de> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] mlx5/core: Use memdup_user() rather than duplicating its implementation |
| Date | 2016-08-20 11:40 +0200 |
| Message-ID | <s8aUV-1bi-1@gated-at.bofh.it> (permalink) |
| References | <qEuGl-43C-5@gated-at.bofh.it> <s87DH-7Jv-13@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Am 20.08.2016 08:01, schrieb SF Markus Elfring:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 20 Aug 2016 07:50:09 +0200
>
> * 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: Markus Elfring <elfring@users.sourceforge.net>
> ---
> drivers/net/ethernet/mellanox/mlx5/core/cmd.c | 17 +++--------------
> 1 file changed, 3 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> index 6388bc0..bb89f04 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/cmd.c
> @@ -1132,7 +1132,6 @@ static ssize_t data_write(struct file *filp, const char __user *buf,
> struct mlx5_core_dev *dev = filp->private_data;
> struct mlx5_cmd_debug *dbg = &dev->cmd.dbg;
> void *ptr;
> - int err;
>
> if (*pos != 0)
> return -EINVAL;
> @@ -1140,25 +1139,15 @@ static ssize_t data_write(struct file *filp, const char __user *buf,
> kfree(dbg->in_msg);
> dbg->in_msg = NULL;
> dbg->inlen = 0;
> -
> - ptr = kzalloc(count, GFP_KERNEL);
> - if (!ptr)
> - return -ENOMEM;
> -
> - if (copy_from_user(ptr, buf, count)) {
> - err = -EFAULT;
> - goto out;
> - }
> + ptr = memdup_user(buf, count);
> + if (IS_ERR(ptr))
> + return PTR_ERR(ptr);
> dbg->in_msg = ptr;
> dbg->inlen = count;
>
> *pos = count;
>
maybe i am missing something here but why do you need ptr ?
The use of count looks even more confusing it is stored in
dbg->inlen, *pos and is returned.
is that realy needed ?
re,
wh
> return count;
> -
> -out:
> - kfree(ptr);
> - return err;
> }
>
> static ssize_t data_read(struct file *filp, char __user *buf, size_t count,
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] mlx5/core: Use memdup_user() rather than duplicating its implementation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-08-20 08:10 +0200 Re: [PATCH] mlx5/core: Use memdup_user() rather than duplicating its implementation walter harms <wharms@bfs.de> - 2016-08-20 11:40 +0200 Re: [PATCH] mlx5/core: Use memdup_user() rather than duplicating its implementation David Miller <davem@davemloft.net> - 2016-08-23 02:10 +0200
csiph-web