linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] misc: xilinx_sdfec: Adjustments for xsdfec_add_ldpc()
@ 2019-11-05 18:52 Markus Elfring
  2019-11-05 18:54 ` [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation Markus Elfring
  2019-11-05 18:56 ` [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc() Markus Elfring
  0 siblings, 2 replies; 7+ messages in thread
From: Markus Elfring @ 2019-11-05 18:52 UTC (permalink / raw)
  To: linux-arm-kernel, Arnd Bergmann, Derek Kiernan, Dragan Cvetic,
	Greg Kroah-Hartman, Michal Simek
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation
  2019-11-05 18:52 [PATCH 0/2] misc: xilinx_sdfec: Adjustments for xsdfec_add_ldpc() Markus Elfring
@ 2019-11-05 18:54 ` Markus Elfring
  2019-11-07 15:40   ` Dragan Cvetic
  2019-11-10 22:18   ` Dragan Cvetic
  2019-11-05 18:56 ` [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc() Markus Elfring
  1 sibling, 2 replies; 7+ messages in thread
From: Markus Elfring @ 2019-11-05 18:54 UTC (permalink / raw)
  To: linux-arm-kernel, Arnd Bergmann, Derek Kiernan, Dragan Cvetic,
	Greg Kroah-Hartman, Michal Simek
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()
  2019-11-05 18:52 [PATCH 0/2] misc: xilinx_sdfec: Adjustments for xsdfec_add_ldpc() Markus Elfring
  2019-11-05 18:54 ` [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation Markus Elfring
@ 2019-11-05 18:56 ` Markus Elfring
  2019-11-07 16:30   ` Dragan Cvetic
  2019-11-07 21:58   ` Dragan Cvetic
  1 sibling, 2 replies; 7+ messages in thread
From: Markus Elfring @ 2019-11-05 18:56 UTC (permalink / raw)
  To: linux-arm-kernel, Arnd Bergmann, Derek Kiernan, Dragan Cvetic,
	Greg Kroah-Hartman, Michal Simek
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
 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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* RE: [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation
  2019-11-05 18:54 ` [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation Markus Elfring
@ 2019-11-07 15:40   ` Dragan Cvetic
  2019-11-10 22:18   ` Dragan Cvetic
  1 sibling, 0 replies; 7+ messages in thread
From: Dragan Cvetic @ 2019-11-07 15:40 UTC (permalink / raw)
  To: Markus Elfring, linux-arm-kernel, Arnd Bergmann, Derek Kiernan,
	Greg Kroah-Hartman, Michal Simek
  Cc: LKML, kernel-janitors

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:Markus.Elfring@web.de]
> Sent: Tuesday 5 November 2019 18:55
> To: linux-arm-kernel@lists.infradead.org; Arnd Bergmann <arnd@arndb.de>; Derek Kiernan <dkiernan@xilinx.com>; Dragan Cvetic
> <draganc@xilinx.com>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Michal Simek <michals@xilinx.com>
> Cc: LKML <linux-kernel@vger.kernel.org>; kernel-janitors@vger.kernel.org
> Subject: [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation
> 
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
> ---
>  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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()
  2019-11-05 18:56 ` [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc() Markus Elfring
@ 2019-11-07 16:30   ` Dragan Cvetic
  2019-11-07 21:58   ` Dragan Cvetic
  1 sibling, 0 replies; 7+ messages in thread
From: Dragan Cvetic @ 2019-11-07 16:30 UTC (permalink / raw)
  To: Markus Elfring, linux-arm-kernel, Arnd Bergmann, Derek Kiernan,
	Greg Kroah-Hartman, Michal Simek
  Cc: LKML, kernel-janitors


Hi Markus,


> -----Original Message-----
> From: Markus Elfring [mailto:Markus.Elfring@web.de]
> Sent: Tuesday 5 November 2019 18:56
> To: linux-arm-kernel@lists.infradead.org; Arnd Bergmann <arnd@arndb.de>; Derek Kiernan <dkiernan@xilinx.com>; Dragan Cvetic
> <draganc@xilinx.com>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Michal Simek <michals@xilinx.com>
> Cc: LKML <linux-kernel@vger.kernel.org>; kernel-janitors@vger.kernel.org
> Subject: [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()
> 
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
> ---
>  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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()
  2019-11-05 18:56 ` [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc() Markus Elfring
  2019-11-07 16:30   ` Dragan Cvetic
@ 2019-11-07 21:58   ` Dragan Cvetic
  1 sibling, 0 replies; 7+ messages in thread
From: Dragan Cvetic @ 2019-11-07 21:58 UTC (permalink / raw)
  To: Markus Elfring, linux-arm-kernel, Arnd Bergmann, Derek Kiernan,
	Greg Kroah-Hartman, Michal Simek
  Cc: LKML, kernel-janitors



> -----Original Message-----
> From: Markus Elfring [mailto:Markus.Elfring@web.de]
> Sent: Tuesday 5 November 2019 18:56
> To: linux-arm-kernel@lists.infradead.org; Arnd Bergmann <arnd@arndb.de>; Derek Kiernan <dkiernan@xilinx.com>; Dragan Cvetic
> <draganc@xilinx.com>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Michal Simek <michals@xilinx.com>
> Cc: LKML <linux-kernel@vger.kernel.org>; kernel-janitors@vger.kernel.org
> Subject: [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc()
> 
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
> ---
>  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 <dragan.cvetic@xilinx.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation
  2019-11-05 18:54 ` [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation Markus Elfring
  2019-11-07 15:40   ` Dragan Cvetic
@ 2019-11-10 22:18   ` Dragan Cvetic
  1 sibling, 0 replies; 7+ messages in thread
From: Dragan Cvetic @ 2019-11-10 22:18 UTC (permalink / raw)
  To: Markus Elfring, linux-arm-kernel, Arnd Bergmann, Derek Kiernan,
	Greg Kroah-Hartman, Michal Simek
  Cc: LKML, kernel-janitors

Hi Markus,


> -----Original Message-----
> From: Markus Elfring [mailto:Markus.Elfring@web.de]
> Sent: Tuesday 5 November 2019 18:55
> To: linux-arm-kernel@lists.infradead.org; Arnd Bergmann <arnd@arndb.de>; Derek Kiernan <dkiernan@xilinx.com>; Dragan Cvetic
> <draganc@xilinx.com>; Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Michal Simek <michals@xilinx.com>
> Cc: LKML <linux-kernel@vger.kernel.org>; kernel-janitors@vger.kernel.org
> Subject: [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation
> 
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
> ---
>  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 <dragan.cvetic@xilinx.com>

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-11-10 22:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-05 18:52 [PATCH 0/2] misc: xilinx_sdfec: Adjustments for xsdfec_add_ldpc() Markus Elfring
2019-11-05 18:54 ` [PATCH 1/2] misc: xilinx_sdfec: Use memdup_user() rather than duplicating its implementation Markus Elfring
2019-11-07 15:40   ` Dragan Cvetic
2019-11-10 22:18   ` Dragan Cvetic
2019-11-05 18:56 ` [PATCH 2/2] misc: xilinx_sdfec: Combine three condition checks into one statement in xsdfec_add_ldpc() Markus Elfring
2019-11-07 16:30   ` Dragan Cvetic
2019-11-07 21:58   ` 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).