From: SF Markus Elfring <elfring@users.sourceforge.net>
To: linux-rdma@vger.kernel.org, netdev@vger.kernel.org,
Leon Romanovsky <leonro@mellanox.com>,
Matan Barak <matanb@mellanox.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org,
Julia Lawall <julia.lawall@lip6.fr>
Subject: [PATCH] mlx5/core: Use memdup_user() rather than duplicating its implementation
Date: Sat, 20 Aug 2016 08:01:22 +0200 [thread overview]
Message-ID: <ceb39933-438d-920d-f294-ea0ce32fd171@users.sourceforge.net> (raw)
In-Reply-To: <566ABCD9.1060404@users.sourceforge.net>
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;
return count;
-
-out:
- kfree(ptr);
- return err;
}
static ssize_t data_read(struct file *filp, char __user *buf, size_t count,
--
2.9.3
next prev parent reply other threads:[~2016-08-20 6:01 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <566ABCD9.1060404@users.sourceforge.net>
2015-12-26 18:39 ` [PATCH 0/6] InfiniBand-ocrdma: Fine-tuning for some function implementations SF Markus Elfring
2015-12-26 18:43 ` [PATCH 1/6] InfiniBand-ocrdma: One variable and jump label less in ocrdma_alloc_ucontext_pd() SF Markus Elfring
2015-12-26 19:41 ` kbuild test robot
2015-12-26 21:28 ` [PATCH v2 1/6] InfiniBand-ocrdma: One " SF Markus Elfring
2016-01-11 13:11 ` Selvin Xavier
[not found] ` <567EDED5.4040201-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2015-12-26 18:45 ` [PATCH 2/6] InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions SF Markus Elfring
2015-12-26 18:47 ` [PATCH 3/6] InfiniBand-ocrdma: Returning only value constants in ocrdma_qp_state_change() SF Markus Elfring
2015-12-26 18:49 ` [PATCH 4/6] InfiniBand-ocrdma: Return a value from a function call in _ocrdma_modify_qp() directly SF Markus Elfring
2016-01-14 17:18 ` [PATCH v3 0/6] InfiniBand-ocrdma: Fine-tuning for some function implementations SF Markus Elfring
[not found] ` <5697D865.5010507-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2016-01-14 17:38 ` [PATCH v3 1/6] InfiniBand-ocrdma: One jump label less in ocrdma_alloc_ucontext_pd() SF Markus Elfring
2016-01-14 17:50 ` [PATCH v3 5/6] InfiniBand-ocrdma: Returning only value constants in ocrdma_resize_cq() SF Markus Elfring
2016-01-14 17:43 ` [PATCH v3 2/6] InfiniBand-ocrdma: Delete unnecessary variable initialisations in 11 functions SF Markus Elfring
2016-01-15 13:20 ` Leon Romanovsky
[not found] ` <20160115132014.GC30615-2ukJVAZIZ/Y@public.gmane.org>
2016-01-15 14:50 ` SF Markus Elfring
[not found] ` <56990733.7000506-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2016-01-15 15:09 ` Leon Romanovsky
[not found] ` <20160115150935.GA32346-2ukJVAZIZ/Y@public.gmane.org>
2016-01-15 15:26 ` SF Markus Elfring
[not found] ` <56990FAC.6000506-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2016-01-15 15:59 ` Leon Romanovsky
[not found] ` <20160115155938.GB32346-2ukJVAZIZ/Y@public.gmane.org>
2016-01-15 16:10 ` Dan Carpenter
2016-01-15 16:24 ` SF Markus Elfring
[not found] ` <56991D52.8030808-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2016-01-15 17:00 ` Leon Romanovsky
[not found] ` <20160115170048.GC32346-2ukJVAZIZ/Y@public.gmane.org>
2016-01-15 17:19 ` Bart Van Assche
2016-01-15 17:41 ` Leon Romanovsky
2016-01-15 18:19 ` SF Markus Elfring
2016-01-16 6:18 ` Leon Romanovsky
[not found] ` <20160116061843.GE32346-2ukJVAZIZ/Y@public.gmane.org>
2016-01-16 8:30 ` SF Markus Elfring
2016-01-14 17:45 ` [PATCH v3 3/6] InfiniBand-ocrdma: Returning only value constants in ocrdma_qp_state_change() SF Markus Elfring
2016-01-14 17:48 ` [PATCH v3 4/6] InfiniBand-ocrdma: Return a value from a function call in _ocrdma_modify_qp() directly SF Markus Elfring
2016-01-14 17:51 ` [PATCH v3 6/6] InfiniBand-ocrdma: Delete an unnecessary variable in ocrdma_dealloc_pd() SF Markus Elfring
2015-12-26 18:50 ` [PATCH 5/6] InfiniBand-ocrdma: Returning only value constants in ocrdma_resize_cq() SF Markus Elfring
2015-12-26 18:51 ` [PATCH 6/6] InfiniBand-ocrdma: Delete an unnecessary variable in ocrdma_dealloc_pd() SF Markus Elfring
2015-12-27 12:36 ` [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations SF Markus Elfring
2015-12-27 12:40 ` [PATCH 1/2] InfiniBand-iSER: One jump label less in iser_reg_sig_mr() SF Markus Elfring
2015-12-27 12:41 ` [PATCH 2/2] InfiniBand-iSER-target: One jump label less in isert_reg_sig_mr() SF Markus Elfring
[not found] ` <567FDB4E.2040000-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2015-12-27 12:43 ` [PATCH 0/2] InfiniBand-iSER: Refactoring for two function implementations Leon Romanovsky
2015-12-27 12:52 ` Leon Romanovsky
2016-01-06 18:47 ` Nicholas A. Bellinger
2015-12-27 15:26 ` Sagi Grimberg
2016-08-20 6:01 ` SF Markus Elfring [this message]
[not found] ` <ceb39933-438d-920d-f294-ea0ce32fd171-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2016-08-20 9:32 ` [PATCH] mlx5/core: Use memdup_user() rather than duplicating its implementation walter harms
2016-08-23 0:05 ` David Miller
2016-08-21 17:39 ` [PATCH 0/2] IB/core: Fine-tuning for ib_is_udata_cleared() SF Markus Elfring
2016-08-21 17:42 ` [PATCH 1/2] IB/core: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
[not found] ` <f7bb3caf-81cd-fba9-afc8-5fac72b8a4b3-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2016-08-21 17:45 ` [PATCH 2/2] IB/core: Delete an unnecessary initialisation in ib_is_udata_cleared() SF Markus Elfring
2016-08-21 18:03 ` [PATCH 0/2] IB/core: Fine-tuning for ib_is_udata_cleared() Joe Perches
[not found] ` <1471802623.3746.1.camel-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
2016-08-21 19:51 ` SF Markus Elfring
[not found] ` <683187e0-2e6a-88c0-f87a-9c5f0489370a-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
2016-08-21 19:53 ` Joe Perches
[not found] ` <1471809188.3746.18.camel-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
2016-08-21 20:15 ` SF Markus Elfring
2016-08-22 9:46 ` Yann Droneaud
[not found] ` <1471859215.2764.24.camel-RlY5vtjFyJ3QT0dZR+AlfA@public.gmane.org>
2016-08-22 16:30 ` [PATCH v2] IB/core: Use memdup_user() rather than duplicating its implementation SF Markus Elfring
2016-08-23 16:43 ` Doug Ledford
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ceb39933-438d-920d-f294-ea0ce32fd171@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=julia.lawall@lip6.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=leonro@mellanox.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=matanb@mellanox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).