public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6] staging: vt6656: add error code handling to unused variable
@ 2020-03-30 21:46 John B. Wyatt IV
  2020-03-30 22:01 ` Stefano Brivio
  0 siblings, 1 reply; 4+ messages in thread
From: John B. Wyatt IV @ 2020-03-30 21:46 UTC (permalink / raw)
  To: outreachy-kernel, Julia Lawall, Stefano Brivio, Forest Bond,
	Greg Kroah-Hartman, Quentin Deslandes, Colin Ian King,
	Malcolm Priestley, devel, linux-kernel
  Cc: John B. Wyatt IV

Add error code handling to unused 'ret' variable that was never used.
Return an error code from functions called within vnt_radio_power_on.

Issue reported by coccinelle (coccicheck).

Suggested-by: Quentin Deslandes <quentin.deslandes@itdev.co.uk>
Suggested-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: Quentin Deslandes <quentin.deslandes@itdev.co.uk>
Signed-off-by: John B. Wyatt IV <jbwyatt4@gmail.com>
---
v6: Forgot to add all the v5 code to commit.

v5: Remove Suggested-by: Julia Lawall above seperator line.
	Remove break; statement in switch block.
	break; removal checked by both gcc compile and checkpatch.
	Suggested by Stefano Brivio <sbrivio@redhat.com>

v4: Move Suggested-by: Julia Lawall above seperator line.
    Add Reviewed-by tag as requested by Quentin Deslandes.

v3: Forgot to add v2 code changes to commit.

v2: Replace goto statements with return.
    Remove last if check because it was unneeded.
    Suggested-by: Julia Lawall <julia.lawall@inria.fr>

 drivers/staging/vt6656/card.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
index dc3ab10eb630..c947e8188384 100644
--- a/drivers/staging/vt6656/card.c
+++ b/drivers/staging/vt6656/card.c
@@ -723,9 +723,13 @@ int vnt_radio_power_on(struct vnt_private *priv)
 {
 	int ret = 0;
 
-	vnt_exit_deep_sleep(priv);
+	ret = vnt_exit_deep_sleep(priv);
+	if (ret)
+		return ret;
 
-	vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
+	ret = vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
+	if (ret)
+		return ret;
 
 	switch (priv->rf_type) {
 	case RF_AL2230:
@@ -734,14 +738,14 @@ int vnt_radio_power_on(struct vnt_private *priv)
 	case RF_VT3226:
 	case RF_VT3226D0:
 	case RF_VT3342A0:
-		vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
-				    (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
-		break;
+		ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
+					  (SOFTPWRCTL_SWPE2 | 
+					  SOFTPWRCTL_SWPE3));
 	}
+	if (ret)
+		return ret;
 
-	vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD);
-
-	return ret;
+	return vnt_mac_reg_bits_off(priv, MAC_REG_GPIOCTL1, GPIO3_INTMD);
 }
 
 void vnt_set_bss_mode(struct vnt_private *priv)
-- 
2.25.1


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

* Re: [PATCH v6] staging: vt6656: add error code handling to unused variable
  2020-03-30 21:46 [PATCH v6] staging: vt6656: add error code handling to unused variable John B. Wyatt IV
@ 2020-03-30 22:01 ` Stefano Brivio
  2020-03-30 22:26   ` John B. Wyatt IV
  0 siblings, 1 reply; 4+ messages in thread
From: Stefano Brivio @ 2020-03-30 22:01 UTC (permalink / raw)
  To: John B. Wyatt IV
  Cc: outreachy-kernel, Julia Lawall, Forest Bond, Greg Kroah-Hartman,
	Quentin Deslandes, Colin Ian King, Malcolm Priestley, devel,
	linux-kernel

On Mon, 30 Mar 2020 14:46:13 -0700
"John B. Wyatt IV" <jbwyatt4@gmail.com> wrote:

> Add error code handling to unused 'ret' variable that was never used.
> Return an error code from functions called within vnt_radio_power_on.
> 
> Issue reported by coccinelle (coccicheck).
> 
> Suggested-by: Quentin Deslandes <quentin.deslandes@itdev.co.uk>
> Suggested-by: Stefano Brivio <sbrivio@redhat.com>
> Reviewed-by: Quentin Deslandes <quentin.deslandes@itdev.co.uk>
> Signed-off-by: John B. Wyatt IV <jbwyatt4@gmail.com>
> ---
> v6: Forgot to add all the v5 code to commit.
> 
> v5: Remove Suggested-by: Julia Lawall above seperator line.
> 	Remove break; statement in switch block.
> 	break; removal checked by both gcc compile and checkpatch.
> 	Suggested by Stefano Brivio <sbrivio@redhat.com>
> 
> v4: Move Suggested-by: Julia Lawall above seperator line.
>     Add Reviewed-by tag as requested by Quentin Deslandes.
> 
> v3: Forgot to add v2 code changes to commit.
> 
> v2: Replace goto statements with return.
>     Remove last if check because it was unneeded.
>     Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> 
>  drivers/staging/vt6656/card.c | 20 ++++++++++++--------
>  1 file changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/staging/vt6656/card.c b/drivers/staging/vt6656/card.c
> index dc3ab10eb630..c947e8188384 100644
> --- a/drivers/staging/vt6656/card.c
> +++ b/drivers/staging/vt6656/card.c
> @@ -723,9 +723,13 @@ int vnt_radio_power_on(struct vnt_private *priv)
>  {
>  	int ret = 0;
>  
> -	vnt_exit_deep_sleep(priv);
> +	ret = vnt_exit_deep_sleep(priv);
> +	if (ret)
> +		return ret;
>  
> -	vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
> +	ret = vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
> +	if (ret)
> +		return ret;
>  
>  	switch (priv->rf_type) {
>  	case RF_AL2230:
> @@ -734,14 +738,14 @@ int vnt_radio_power_on(struct vnt_private *priv)
>  	case RF_VT3226:
>  	case RF_VT3226D0:
>  	case RF_VT3342A0:
> -		vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
> -				    (SOFTPWRCTL_SWPE2 | SOFTPWRCTL_SWPE3));
> -		break;
> +		ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
> +					  (SOFTPWRCTL_SWPE2 | 
> +					  SOFTPWRCTL_SWPE3));
>  	}
> +	if (ret)
> +		return ret;

Hmm, sorry, I haven't been clear enough I guess.

This is what you're doing:

if rf_type is not in that list:
- set some bits in a register
- did it fail? return
- did it fail? return
...

if rf_type is in that list:
- set some bits in a register
- did it fail? return
- set some other bits
- did it fail? return
...

Now, the "set some other bits" part is already selected depending on
rf_type. There's no need to check 'ret' otherwise, so you can move the
return just after setting 'ret', in the switch case.

With a check, because you don't want to return if ret == 0.

-- 
Stefano


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

* Re: [PATCH v6] staging: vt6656: add error code handling to unused variable
  2020-03-30 22:01 ` Stefano Brivio
@ 2020-03-30 22:26   ` John B. Wyatt IV
  2020-03-30 22:32     ` Stefano Brivio
  0 siblings, 1 reply; 4+ messages in thread
From: John B. Wyatt IV @ 2020-03-30 22:26 UTC (permalink / raw)
  To: Stefano Brivio
  Cc: outreachy-kernel, Julia Lawall, Forest Bond, Greg Kroah-Hartman,
	Quentin Deslandes, Colin Ian King, Malcolm Priestley, devel,
	linux-kernel

On Tue, 2020-03-31 at 00:01 +0200, Stefano Brivio wrote:
> On Mon, 30 Mar 2020 14:46:13 -0700
> "John B. Wyatt IV" <jbwyatt4@gmail.com> wrote:
> 
> > Add error code handling to unused 'ret' variable that was never
> > used.
> > Return an error code from functions called within
> > vnt_radio_power_on.
> > 
> > Issue reported by coccinelle (coccicheck).
> > 
> > Suggested-by: Quentin Deslandes <quentin.deslandes@itdev.co.uk>
> > Suggested-by: Stefano Brivio <sbrivio@redhat.com>
> > Reviewed-by: Quentin Deslandes <quentin.deslandes@itdev.co.uk>
> > Signed-off-by: John B. Wyatt IV <jbwyatt4@gmail.com>
> > ---
> > v6: Forgot to add all the v5 code to commit.
> > 
> > v5: Remove Suggested-by: Julia Lawall above seperator line.
> > 	Remove break; statement in switch block.
> > 	break; removal checked by both gcc compile and checkpatch.
> > 	Suggested by Stefano Brivio <sbrivio@redhat.com>
> > 
> > v4: Move Suggested-by: Julia Lawall above seperator line.
> >     Add Reviewed-by tag as requested by Quentin Deslandes.
> > 
> > v3: Forgot to add v2 code changes to commit.
> > 
> > v2: Replace goto statements with return.
> >     Remove last if check because it was unneeded.
> >     Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> > 
> >  drivers/staging/vt6656/card.c | 20 ++++++++++++--------
> >  1 file changed, 12 insertions(+), 8 deletions(-)
> > 
> > diff --git a/drivers/staging/vt6656/card.c
> > b/drivers/staging/vt6656/card.c
> > index dc3ab10eb630..c947e8188384 100644
> > --- a/drivers/staging/vt6656/card.c
> > +++ b/drivers/staging/vt6656/card.c
> > @@ -723,9 +723,13 @@ int vnt_radio_power_on(struct vnt_private
> > *priv)
> >  {
> >  	int ret = 0;
> >  
> > -	vnt_exit_deep_sleep(priv);
> > +	ret = vnt_exit_deep_sleep(priv);
> > +	if (ret)
> > +		return ret;
> >  
> > -	vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
> > +	ret = vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
> > +	if (ret)
> > +		return ret;
> >  
> >  	switch (priv->rf_type) {
> >  	case RF_AL2230:
> > @@ -734,14 +738,14 @@ int vnt_radio_power_on(struct vnt_private
> > *priv)
> >  	case RF_VT3226:
> >  	case RF_VT3226D0:
> >  	case RF_VT3342A0:
> > -		vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
> > -				    (SOFTPWRCTL_SWPE2 |
> > SOFTPWRCTL_SWPE3));
> > -		break;
> > +		ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
> > +					  (SOFTPWRCTL_SWPE2 | 
> > +					  SOFTPWRCTL_SWPE3));
> >  	}
> > +	if (ret)
> > +		return ret;
> 
> Hmm, sorry, I haven't been clear enough I guess.
> 
> This is what you're doing:
> 
> if rf_type is not in that list:
> - set some bits in a register
> - did it fail? return
> - did it fail? return
> ...
> 
> if rf_type is in that list:
> - set some bits in a register
> - did it fail? return
> - set some other bits
> - did it fail? return
> ...
> 
> Now, the "set some other bits" part is already selected depending on
> rf_type. There's no need to check 'ret' otherwise, so you can move
> the
> return just after setting 'ret', in the switch case.
> 

Thank you for pointing that out Stefano. That would be a serious issue
with logic.

Just to be sure. Are you looking for this?

switch (priv->rf_type) {
case RF_AL2230:
case RF_AL2230S:
case RF_AIROHA7230:
case RF_VT3226:
case RF_VT3226D0:
case RF_VT3342A0:
	ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
				  (SOFTPWRCTL_SWPE2 | 
				  SOFTPWRCTL_SWPE3));
	if (ret)
		return ret;
}

> With a check, because you don't want to return if ret == 0.
> 

What do you mean exactly by this?

The new code should only return a 0 at the end of the function with the
vnt_mac_reg_bits_off call.



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

* Re: [PATCH v6] staging: vt6656: add error code handling to unused variable
  2020-03-30 22:26   ` John B. Wyatt IV
@ 2020-03-30 22:32     ` Stefano Brivio
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Brivio @ 2020-03-30 22:32 UTC (permalink / raw)
  To: John B. Wyatt IV
  Cc: outreachy-kernel, Julia Lawall, Forest Bond, Greg Kroah-Hartman,
	Quentin Deslandes, Colin Ian King, Malcolm Priestley, devel,
	linux-kernel

On Mon, 30 Mar 2020 15:26:04 -0700
"John B. Wyatt IV" <jbwyatt4@gmail.com> wrote:

> On Tue, 2020-03-31 at 00:01 +0200, Stefano Brivio wrote:
> > On Mon, 30 Mar 2020 14:46:13 -0700
> > "John B. Wyatt IV" <jbwyatt4@gmail.com> wrote:
> >   
> > > Add error code handling to unused 'ret' variable that was never
> > > used.
> > > Return an error code from functions called within
> > > vnt_radio_power_on.
> > > 
> > > Issue reported by coccinelle (coccicheck).
> > > 
> > > Suggested-by: Quentin Deslandes <quentin.deslandes@itdev.co.uk>
> > > Suggested-by: Stefano Brivio <sbrivio@redhat.com>
> > > Reviewed-by: Quentin Deslandes <quentin.deslandes@itdev.co.uk>
> > > Signed-off-by: John B. Wyatt IV <jbwyatt4@gmail.com>
> > > ---
> > > v6: Forgot to add all the v5 code to commit.
> > > 
> > > v5: Remove Suggested-by: Julia Lawall above seperator line.
> > > 	Remove break; statement in switch block.
> > > 	break; removal checked by both gcc compile and checkpatch.
> > > 	Suggested by Stefano Brivio <sbrivio@redhat.com>
> > > 
> > > v4: Move Suggested-by: Julia Lawall above seperator line.
> > >     Add Reviewed-by tag as requested by Quentin Deslandes.
> > > 
> > > v3: Forgot to add v2 code changes to commit.
> > > 
> > > v2: Replace goto statements with return.
> > >     Remove last if check because it was unneeded.
> > >     Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> > > 
> > >  drivers/staging/vt6656/card.c | 20 ++++++++++++--------
> > >  1 file changed, 12 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/drivers/staging/vt6656/card.c
> > > b/drivers/staging/vt6656/card.c
> > > index dc3ab10eb630..c947e8188384 100644
> > > --- a/drivers/staging/vt6656/card.c
> > > +++ b/drivers/staging/vt6656/card.c
> > > @@ -723,9 +723,13 @@ int vnt_radio_power_on(struct vnt_private
> > > *priv)
> > >  {
> > >  	int ret = 0;
> > >  
> > > -	vnt_exit_deep_sleep(priv);
> > > +	ret = vnt_exit_deep_sleep(priv);
> > > +	if (ret)
> > > +		return ret;
> > >  
> > > -	vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
> > > +	ret = vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_RXON);
> > > +	if (ret)
> > > +		return ret;
> > >  
> > >  	switch (priv->rf_type) {
> > >  	case RF_AL2230:
> > > @@ -734,14 +738,14 @@ int vnt_radio_power_on(struct vnt_private
> > > *priv)
> > >  	case RF_VT3226:
> > >  	case RF_VT3226D0:
> > >  	case RF_VT3342A0:
> > > -		vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
> > > -				    (SOFTPWRCTL_SWPE2 |
> > > SOFTPWRCTL_SWPE3));
> > > -		break;
> > > +		ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
> > > +					  (SOFTPWRCTL_SWPE2 | 
> > > +					  SOFTPWRCTL_SWPE3));
> > >  	}
> > > +	if (ret)
> > > +		return ret;  
> > 
> > Hmm, sorry, I haven't been clear enough I guess.
> > 
> > This is what you're doing:
> > 
> > if rf_type is not in that list:
> > - set some bits in a register
> > - did it fail? return
> > - did it fail? return
> > ...
> > 
> > if rf_type is in that list:
> > - set some bits in a register
> > - did it fail? return
> > - set some other bits
> > - did it fail? return
> > ...
> > 
> > Now, the "set some other bits" part is already selected depending on
> > rf_type. There's no need to check 'ret' otherwise, so you can move
> > the
> > return just after setting 'ret', in the switch case.
> >   
> 
> Thank you for pointing that out Stefano. That would be a serious issue
> with logic.
> 
> Just to be sure. Are you looking for this?
> 
> switch (priv->rf_type) {
> case RF_AL2230:
> case RF_AL2230S:
> case RF_AIROHA7230:
> case RF_VT3226:
> case RF_VT3226D0:
> case RF_VT3342A0:
> 	ret = vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL,
> 				  (SOFTPWRCTL_SWPE2 | 
> 				  SOFTPWRCTL_SWPE3));
> 	if (ret)
> 		return ret;
> }

Exactly.

> > With a check, because you don't want to return if ret == 0.
> >   
> 
> What do you mean exactly by this?

Exactly what you wrote above: if (ret) ...

> The new code should only return a 0 at the end of the function with the
> vnt_mac_reg_bits_off call.

That, or an error code if vnt_mac_reg_bits_off() fails.

-- 
Stefano


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

end of thread, other threads:[~2020-03-30 22:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-30 21:46 [PATCH v6] staging: vt6656: add error code handling to unused variable John B. Wyatt IV
2020-03-30 22:01 ` Stefano Brivio
2020-03-30 22:26   ` John B. Wyatt IV
2020-03-30 22:32     ` Stefano Brivio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox