* [PATCH -next] misc: xilinx_sdfec: Use memdup_user() as a cleanup
@ 2020-04-22 2:58 Zou Wei
2020-04-26 16:01 ` Dragan Cvetic
0 siblings, 1 reply; 2+ messages in thread
From: Zou Wei @ 2020-04-22 2:58 UTC (permalink / raw)
To: derek.kiernan, dragan.cvetic, arnd, gregkh, michal.simek
Cc: linux-arm-kernel, linux-kernel, Zou Wei
Fix coccicheck warning which recommends to use memdup_user().
This patch fixes the following coccicheck warnings:
drivers/misc/xilinx_sdfec.c:652:8-15: WARNING opportunity for memdup_user
Fixes: 20ec628e8007 ("misc: xilinx_sdfec: Add ability to configure LDPC")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zou Wei <zou_wei@huawei.com>
---
drivers/misc/xilinx_sdfec.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
index 71bbaa5..7a75894 100644
--- a/drivers/misc/xilinx_sdfec.c
+++ b/drivers/misc/xilinx_sdfec.c
@@ -649,14 +649,9 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)
struct xsdfec_ldpc_params *ldpc;
int ret, n;
- ldpc = kzalloc(sizeof(*ldpc), GFP_KERNEL);
- if (!ldpc)
- return -ENOMEM;
-
- if (copy_from_user(ldpc, arg, sizeof(*ldpc))) {
- ret = -EFAULT;
- goto err_out;
- }
+ ldpc = memdup_user(arg, sizeof(*ldpc));
+ if (IS_ERR(ldpc))
+ return PTR_ERR(ldpc);
if (xsdfec->config.code == XSDFEC_TURBO_CODE) {
ret = -EIO;
--
2.6.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [PATCH -next] misc: xilinx_sdfec: Use memdup_user() as a cleanup
2020-04-22 2:58 [PATCH -next] misc: xilinx_sdfec: Use memdup_user() as a cleanup Zou Wei
@ 2020-04-26 16:01 ` Dragan Cvetic
0 siblings, 0 replies; 2+ messages in thread
From: Dragan Cvetic @ 2020-04-26 16:01 UTC (permalink / raw)
To: Zou Wei, Derek Kiernan, arnd, gregkh, Michal Simek
Cc: linux-arm-kernel, linux-kernel
Hi Zou,
Thanks for fixing the warning.
> -----Original Message-----
> From: Zou Wei <zou_wei@huawei.com>
> Sent: Wednesday 22 April 2020 03:59
> To: Derek Kiernan <dkiernan@xilinx.com>; Dragan Cvetic <draganc@xilinx.com>; arnd@arndb.de; gregkh@linuxfoundation.org;
> Michal Simek <michals@xilinx.com>
> Cc: linux-arm-kernel@lists.infradead.org; linux-kernel@vger.kernel.org; Zou Wei <zou_wei@huawei.com>
> Subject: [PATCH -next] misc: xilinx_sdfec: Use memdup_user() as a cleanup
>
> Fix coccicheck warning which recommends to use memdup_user().
>
> This patch fixes the following coccicheck warnings:
>
> drivers/misc/xilinx_sdfec.c:652:8-15: WARNING opportunity for memdup_user
>
> Fixes: 20ec628e8007 ("misc: xilinx_sdfec: Add ability to configure LDPC")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zou Wei <zou_wei@huawei.com>
> ---
> drivers/misc/xilinx_sdfec.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
> index 71bbaa5..7a75894 100644
> --- a/drivers/misc/xilinx_sdfec.c
> +++ b/drivers/misc/xilinx_sdfec.c
> @@ -649,14 +649,9 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)
> struct xsdfec_ldpc_params *ldpc;
> int ret, n;
>
> - ldpc = kzalloc(sizeof(*ldpc), GFP_KERNEL);
> - if (!ldpc)
> - return -ENOMEM;
> -
> - if (copy_from_user(ldpc, arg, sizeof(*ldpc))) {
> - ret = -EFAULT;
> - goto err_out;
> - }
> + ldpc = memdup_user(arg, sizeof(*ldpc));
> + if (IS_ERR(ldpc))
> + return PTR_ERR(ldpc);
>
> if (xsdfec->config.code == XSDFEC_TURBO_CODE) {
> ret = -EIO;
> --
> 2.6.2
Acked-by: Dragan Cvetic <dragan.cvetic@xilinx.com>
Regards
Dragan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-04-26 16:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-22 2:58 [PATCH -next] misc: xilinx_sdfec: Use memdup_user() as a cleanup Zou Wei
2020-04-26 16:01 ` Dragan Cvetic
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).