2019-11-05 18:53:57

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/2] misc: xilinx_sdfec: Adjustments for xsdfec_add_ldpc()

From: Markus Elfring <[email protected]>
Date: Tue, 5 Nov 2019 19:45:05 +0100

Two update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Use memdup_user() rather than duplicating its implementation
Combine three condition checks into one statement

drivers/misc/xilinx_sdfec.c | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)

--
2.24.0


2019-11-05 18:57:16

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation

From: Markus Elfring <[email protected]>
Date: Tue, 5 Nov 2019 19:09:15 +0100

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

Generated by: scripts/coccinelle/api/memdup_user.cocci

Fixes: 20ec628e8007ec75c2f884e00004f39eab6289b5 ("misc: xilinx_sdfec: Add ability to configure LDPC")
Signed-off-by: Markus Elfring <[email protected]>
---
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 11835969e982..a622fcf4954a 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.24.0

2019-11-05 18:58:05

by Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()

From: Markus Elfring <[email protected]>
Date: Tue, 5 Nov 2019 19:32:25 +0100

The same return code was set after three condition checks.
Thus use a single statement instead.

Fixes: 20ec628e8007ec75c2f884e00004f39eab6289b5 ("misc: xilinx_sdfec: Add ability to configure LDPC")
Signed-off-by: Markus Elfring <[email protected]>
---
drivers/misc/xilinx_sdfec.c | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
index a622fcf4954a..322d5c6e6d12 100644
--- a/drivers/misc/xilinx_sdfec.c
+++ b/drivers/misc/xilinx_sdfec.c
@@ -653,18 +653,10 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)
if (IS_ERR(ldpc))
return PTR_ERR(ldpc);

- if (xsdfec->config.code == XSDFEC_TURBO_CODE) {
- ret = -EIO;
- goto err_out;
- }
-
- /* Verify Device has not started */
- if (xsdfec->state == XSDFEC_STARTED) {
- ret = -EIO;
- goto err_out;
- }
-
- if (xsdfec->config.code_wr_protect) {
+ if (xsdfec->config.code == XSDFEC_TURBO_CODE ||
+ /* Verify device has not started */
+ xsdfec->state == XSDFEC_STARTED ||
+ xsdfec->config.code_wr_protect) {
ret = -EIO;
goto err_out;
}
--
2.24.0

2019-11-07 15:43:56

by Dragan Cvetic

[permalink] [raw]
Subject: RE: [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation

HI Markus,

Thanks for the nice solution,
we are going to test this change and let you know about the result.

Regards
Dragan


> -----Original Message-----
> From: Markus Elfring [mailto:[email protected]]
> Sent: Tuesday 5 November 2019 18:55
> To: [email protected]; Arnd Bergmann <[email protected]>; Derek Kiernan <[email protected]>; Dragan Cvetic
> <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>
> Cc: LKML <[email protected]>; [email protected]
> Subject: [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation
>
> From: Markus Elfring <[email protected]>
> Date: Tue, 5 Nov 2019 19:09:15 +0100
>
> Reuse existing functionality from memdup_user() instead of keeping
> duplicate source code.
>
> Generated by: scripts/coccinelle/api/memdup_user.cocci
>
> Fixes: 20ec628e8007ec75c2f884e00004f39eab6289b5 ("misc: xilinx_sdfec: Add ability to configure LDPC")
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> 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 11835969e982..a622fcf4954a 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.24.0

2019-11-07 16:31:42

by Dragan Cvetic

[permalink] [raw]
Subject: RE: [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()


Hi Markus,


> -----Original Message-----
> From: Markus Elfring [mailto:[email protected]]
> Sent: Tuesday 5 November 2019 18:56
> To: [email protected]; Arnd Bergmann <[email protected]>; Derek Kiernan <[email protected]>; Dragan Cvetic
> <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>
> Cc: LKML <[email protected]>; [email protected]
> Subject: [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()
>
> From: Markus Elfring <[email protected]>
> Date: Tue, 5 Nov 2019 19:32:25 +0100
>
> The same return code was set after three condition checks.
> Thus use a single statement instead.
>
> Fixes: 20ec628e8007ec75c2f884e00004f39eab6289b5 ("misc: xilinx_sdfec: Add ability to configure LDPC")
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/misc/xilinx_sdfec.c | 16 ++++------------
> 1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
> index a622fcf4954a..322d5c6e6d12 100644
> --- a/drivers/misc/xilinx_sdfec.c
> +++ b/drivers/misc/xilinx_sdfec.c
> @@ -653,18 +653,10 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)
> if (IS_ERR(ldpc))
> return PTR_ERR(ldpc);
>
> - if (xsdfec->config.code == XSDFEC_TURBO_CODE) {
> - ret = -EIO;
> - goto err_out;
> - }
> -
> - /* Verify Device has not started */
> - if (xsdfec->state == XSDFEC_STARTED) {
> - ret = -EIO;
> - goto err_out;
> - }
> -
> - if (xsdfec->config.code_wr_protect) {
> + if (xsdfec->config.code == XSDFEC_TURBO_CODE ||
> + /* Verify device has not started */
> + xsdfec->state == XSDFEC_STARTED ||
> + xsdfec->config.code_wr_protect) {
> ret = -EIO;
> goto err_out;
> }

approved

> --
> 2.24.0

2019-11-07 22:01:36

by Dragan Cvetic

[permalink] [raw]
Subject: RE: [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()



> -----Original Message-----
> From: Markus Elfring [mailto:[email protected]]
> Sent: Tuesday 5 November 2019 18:56
> To: [email protected]; Arnd Bergmann <[email protected]>; Derek Kiernan <[email protected]>; Dragan Cvetic
> <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>
> Cc: LKML <[email protected]>; [email protected]
> Subject: [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()
>
> From: Markus Elfring <[email protected]>
> Date: Tue, 5 Nov 2019 19:32:25 +0100
>
> The same return code was set after three condition checks.
> Thus use a single statement instead.
>
> Fixes: 20ec628e8007ec75c2f884e00004f39eab6289b5 ("misc: xilinx_sdfec: Add ability to configure LDPC")
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> drivers/misc/xilinx_sdfec.c | 16 ++++------------
> 1 file changed, 4 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/misc/xilinx_sdfec.c b/drivers/misc/xilinx_sdfec.c
> index a622fcf4954a..322d5c6e6d12 100644
> --- a/drivers/misc/xilinx_sdfec.c
> +++ b/drivers/misc/xilinx_sdfec.c
> @@ -653,18 +653,10 @@ static int xsdfec_add_ldpc(struct xsdfec_dev *xsdfec, void __user *arg)
> if (IS_ERR(ldpc))
> return PTR_ERR(ldpc);
>
> - if (xsdfec->config.code == XSDFEC_TURBO_CODE) {
> - ret = -EIO;
> - goto err_out;
> - }
> -
> - /* Verify Device has not started */
> - if (xsdfec->state == XSDFEC_STARTED) {
> - ret = -EIO;
> - goto err_out;
> - }
> -
> - if (xsdfec->config.code_wr_protect) {
> + if (xsdfec->config.code == XSDFEC_TURBO_CODE ||
> + /* Verify device has not started */
> + xsdfec->state == XSDFEC_STARTED ||
> + xsdfec->config.code_wr_protect) {
> ret = -EIO;
> goto err_out;
> }
> --
> 2.24.0

Acked-by: Dragan Cvetic <[email protected]>

2019-11-10 22:19:21

by Dragan Cvetic

[permalink] [raw]
Subject: RE: [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation

Hi Markus,


> -----Original Message-----
> From: Markus Elfring [mailto:[email protected]]
> Sent: Tuesday 5 November 2019 18:55
> To: [email protected]; Arnd Bergmann <[email protected]>; Derek Kiernan <[email protected]>; Dragan Cvetic
> <[email protected]>; Greg Kroah-Hartman <[email protected]>; Michal Simek <[email protected]>
> Cc: LKML <[email protected]>; [email protected]
> Subject: [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation
>
> From: Markus Elfring <[email protected]>
> Date: Tue, 5 Nov 2019 19:09:15 +0100
>
> Reuse existing functionality from memdup_user() instead of keeping
> duplicate source code.
>
> Generated by: scripts/coccinelle/api/memdup_user.cocci
>
> Fixes: 20ec628e8007ec75c2f884e00004f39eab6289b5 ("misc: xilinx_sdfec: Add ability to configure LDPC")
> Signed-off-by: Markus Elfring <[email protected]>
> ---
> 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 11835969e982..a622fcf4954a 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);

Acked-by: Dragan Cvetic <[email protected]>

>
> if (xsdfec->config.code == XSDFEC_TURBO_CODE) {
> ret = -EIO;
> --
> 2.24.0