LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] staging: rtl8723bs: core: remove redundant zero'ing of counter variable k
@ 2020-02-23 15:28 Colin King
  2020-02-24 11:07 ` AW: " Walter Harms
  0 siblings, 1 reply; 4+ messages in thread
From: Colin King @ 2020-02-23 15:28 UTC (permalink / raw)
  To: Greg Kroah-Hartman, devel; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The zero'ing of counter variable k is redundant as it is never read
after breaking out of the while loop. Remove it.

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/staging/rtl8723bs/core/rtw_efuse.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_efuse.c b/drivers/staging/rtl8723bs/core/rtw_efuse.c
index 3b8848182221..bdb6ff8aab7d 100644
--- a/drivers/staging/rtl8723bs/core/rtw_efuse.c
+++ b/drivers/staging/rtl8723bs/core/rtw_efuse.c
@@ -244,10 +244,8 @@ u16 	Address)
 		while (!(Bytetemp & 0x80)) {
 			Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
 			k++;
-			if (k == 1000) {
-				k = 0;
+			if (k == 1000)
 				break;
-			}
 		}
 		return rtw_read8(Adapter, EFUSE_CTRL);
 	} else
-- 
2.25.0


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

* AW: [PATCH] staging: rtl8723bs: core: remove redundant zero'ing of counter variable k
  2020-02-23 15:28 [PATCH] staging: rtl8723bs: core: remove redundant zero'ing of counter variable k Colin King
@ 2020-02-24 11:07 ` Walter Harms
  2020-02-24 11:27   ` Dan Carpenter
  0 siblings, 1 reply; 4+ messages in thread
From: Walter Harms @ 2020-02-24 11:07 UTC (permalink / raw)
  To: Colin King, Greg Kroah-Hartman, devel; +Cc: kernel-janitors, linux-kernel


________________________________________
Von: kernel-janitors-owner@vger.kernel.org <kernel-janitors-owner@vger.kernel.org> im Auftrag von Colin King <colin.king@canonical.com>
Gesendet: Sonntag, 23. Februar 2020 16:28
An: Greg Kroah-Hartman; devel@driverdev.osuosl.org
Cc: kernel-janitors@vger.kernel.org; linux-kernel@vger.kernel.org
Betreff: [PATCH] staging: rtl8723bs: core: remove redundant zero'ing of counter variable k

From: Colin Ian King <colin.king@canonical.com>

The zero'ing of counter variable k is redundant as it is never read
after breaking out of the while loop. Remove it.

Addresses-Coverity: ("Unused value")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/staging/rtl8723bs/core/rtw_efuse.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8723bs/core/rtw_efuse.c b/drivers/staging/rtl8723bs/core/rtw_efuse.c
index 3b8848182221..bdb6ff8aab7d 100644
--- a/drivers/staging/rtl8723bs/core/rtw_efuse.c
+++ b/drivers/staging/rtl8723bs/core/rtw_efuse.c
@@ -244,10 +244,8 @@ u16        Address)
                while (!(Bytetemp & 0x80)) {
                        Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
                        k++;
-                       if (k == 1000) {
-                               k = 0;
+                       if (k == 1000)
                                break;
-                       }

IMHO this is confusing to read, i suggest:

 for(k=0;k<1000;k++) {
      Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
      if ( Bytetemp & 0x80 )
               break;
      }

 NTL is am wondering what will happen if k==1000
 and Bytetemp is still invalid. Will rtw_read8() fail or
 simply return invalid data ?

 ym2c,
 re,
 wh
                }
                return rtw_read8(Adapter, EFUSE_CTRL);
        } else
--
2.25.0


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

* Re: [PATCH] staging: rtl8723bs: core: remove redundant zero'ing of counter variable k
  2020-02-24 11:07 ` AW: " Walter Harms
@ 2020-02-24 11:27   ` Dan Carpenter
  2020-02-24 11:36     ` AW: " Walter Harms
  0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2020-02-24 11:27 UTC (permalink / raw)
  To: Walter Harms
  Cc: Colin King, Greg Kroah-Hartman, devel, kernel-janitors, linux-kernel

On Mon, Feb 24, 2020 at 11:07:55AM +0000, Walter Harms wrote:
> diff --git a/drivers/staging/rtl8723bs/core/rtw_efuse.c b/drivers/staging/rtl8723bs/core/rtw_efuse.c
> index 3b8848182221..bdb6ff8aab7d 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_efuse.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_efuse.c
> @@ -244,10 +244,8 @@ u16        Address)
>                 while (!(Bytetemp & 0x80)) {
>                         Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
>                         k++;
> -                       if (k == 1000) {
> -                               k = 0;
> +                       if (k == 1000)
>                                 break;
> -                       }
> 
> IMHO this is confusing to read, i suggest:
> 
>  for(k=0;k<1000;k++) {
>       Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
>       if ( Bytetemp & 0x80 )
>                break;
>       }
> 

The problem with the original code is that the variable is named "k"
instead of "retry".  It should be:

	do {
		Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
	} while (!(Bytetemp & 0x80)) && ++retry < 1000);


>  NTL is am wondering what will happen if k==1000
>  and Bytetemp is still invalid. Will rtw_read8() fail or
>  simply return invalid data ?

Yeah.  That was my thought reviewing this patch as well.

It should probably return 0xff on failure.

	if (retry >= 1000)
		return 0xff;

regards,
dan carpenter


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

* AW: [PATCH] staging: rtl8723bs: core: remove redundant zero'ing of counter variable k
  2020-02-24 11:27   ` Dan Carpenter
@ 2020-02-24 11:36     ` Walter Harms
  0 siblings, 0 replies; 4+ messages in thread
From: Walter Harms @ 2020-02-24 11:36 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Colin King, Greg Kroah-Hartman, devel, kernel-janitors, linux-kernel


________________________________________
Von: Dan Carpenter <dan.carpenter@oracle.com>
Gesendet: Montag, 24. Februar 2020 12:27
An: Walter Harms
Cc: Colin King; Greg Kroah-Hartman; devel@driverdev.osuosl.org; kernel-janitors@vger.kernel.org; linux-kernel@vger.kernel.org
Betreff: Re: [PATCH] staging: rtl8723bs: core: remove redundant zero'ing of counter variable k

On Mon, Feb 24, 2020 at 11:07:55AM +0000, Walter Harms wrote:
> diff --git a/drivers/staging/rtl8723bs/core/rtw_efuse.c b/drivers/staging/rtl8723bs/core/rtw_efuse.c
> index 3b8848182221..bdb6ff8aab7d 100644
> --- a/drivers/staging/rtl8723bs/core/rtw_efuse.c
> +++ b/drivers/staging/rtl8723bs/core/rtw_efuse.c
> @@ -244,10 +244,8 @@ u16        Address)
>                 while (!(Bytetemp & 0x80)) {
>                         Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
>                         k++;
> -                       if (k == 1000) {
> -                               k = 0;
> +                       if (k == 1000)
>                                 break;
> -                       }
>
> IMHO this is confusing to read, i suggest:
>
>  for(k=0;k<1000;k++) {
>       Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
>       if ( Bytetemp & 0x80 )
>                break;
>       }
>

The problem with the original code is that the variable is named "k"
instead of "retry".  It should be:

        do {
                Bytetemp = rtw_read8(Adapter, EFUSE_CTRL+3);
        } while (!(Bytetemp & 0x80)) && ++retry < 1000);

good point,
personally i try to avoid putting to much into braces, so i
would go for the additional if() but this is for the maintainer.


>  NTL is am wondering what will happen if k==1000
>  and Bytetemp is still invalid. Will rtw_read8() fail or
>  simply return invalid data ?

Yeah.  That was my thought reviewing this patch as well.

It should probably return 0xff on failure.

        if (retry >= 1000)
                return 0xff;

looks nice,

re,
 wh
regards,
dan carpenter


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

end of thread, other threads:[~2020-02-24 11:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-23 15:28 [PATCH] staging: rtl8723bs: core: remove redundant zero'ing of counter variable k Colin King
2020-02-24 11:07 ` AW: " Walter Harms
2020-02-24 11:27   ` Dan Carpenter
2020-02-24 11:36     ` AW: " Walter Harms

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).