linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wilc1000: fix a loop timeout condition
@ 2021-03-19 14:47 Dan Carpenter
  2021-03-19 16:09 ` Ajay.Kathat
  2021-04-17 17:54 ` Kalle Valo
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Carpenter @ 2021-03-19 14:47 UTC (permalink / raw)
  To: Ajay Singh
  Cc: Claudiu Beznea, Kalle Valo, David Mosberger-Tang, linux-wireless,
	kernel-janitors

If the loop fails, the "while(trials--) {" loop will exit with "trials"
set to -1.  The test for that expects it to end with "trials" set to 0
so the warning message will not be printed.

Fix this by changing from a post-op to a pre-op.  This does mean that
we only make 99 attempts instead of 100 but that's okay.

Fixes: f135a1571a05 ("wilc1000: Support chip sleep over SPI")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/net/wireless/microchip/wilc1000/wlan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/microchip/wilc1000/wlan.c b/drivers/net/wireless/microchip/wilc1000/wlan.c
index d4a90c490084..2030fc7f53ca 100644
--- a/drivers/net/wireless/microchip/wilc1000/wlan.c
+++ b/drivers/net/wireless/microchip/wilc1000/wlan.c
@@ -575,7 +575,7 @@ void chip_allow_sleep(struct wilc *wilc)
 		to_host_from_fw_bit = WILC_SPI_FW_TO_HOST_BIT;
 	}
 
-	while (trials--) {
+	while (--trials) {
 		ret = hif_func->hif_read_reg(wilc, to_host_from_fw_reg, &reg);
 		if (ret)
 			return;
-- 
2.30.2


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

* Re: [PATCH] wilc1000: fix a loop timeout condition
  2021-03-19 14:47 [PATCH] wilc1000: fix a loop timeout condition Dan Carpenter
@ 2021-03-19 16:09 ` Ajay.Kathat
  2021-03-29 18:47   ` David Mosberger-Tang
  2021-04-17 17:54 ` Kalle Valo
  1 sibling, 1 reply; 5+ messages in thread
From: Ajay.Kathat @ 2021-03-19 16:09 UTC (permalink / raw)
  To: dan.carpenter
  Cc: Claudiu.Beznea, kvalo, davidm, linux-wireless, kernel-janitors


On 19/03/21 8:17 pm, Dan Carpenter wrote:
> 
> If the loop fails, the "while(trials--) {" loop will exit with "trials"
> set to -1.  The test for that expects it to end with "trials" set to 0
> so the warning message will not be printed.
> 
> Fix this by changing from a post-op to a pre-op.  This does mean that
> we only make 99 attempts instead of 100 but that's okay.
> 
> Fixes: f135a1571a05 ("wilc1000: Support chip sleep over SPI")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks Dan.

Acked-by: Ajay Singh <ajay.kathat@microchip.com>

> ---
>  drivers/net/wireless/microchip/wilc1000/wlan.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/wireless/microchip/wilc1000/wlan.c b/drivers/net/wireless/microchip/wilc1000/wlan.c
> index d4a90c490084..2030fc7f53ca 100644
> --- a/drivers/net/wireless/microchip/wilc1000/wlan.c
> +++ b/drivers/net/wireless/microchip/wilc1000/wlan.c
> @@ -575,7 +575,7 @@ void chip_allow_sleep(struct wilc *wilc)
>                 to_host_from_fw_bit = WILC_SPI_FW_TO_HOST_BIT;
>         }
> 
> -       while (trials--) {
> +       while (--trials) {
>                 ret = hif_func->hif_read_reg(wilc, to_host_from_fw_reg, &reg);
>                 if (ret)
>                         return;
> --
> 2.30.2
> 

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

* Re: [PATCH] wilc1000: fix a loop timeout condition
  2021-03-19 16:09 ` Ajay.Kathat
@ 2021-03-29 18:47   ` David Mosberger-Tang
  2021-03-30  8:52     ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: David Mosberger-Tang @ 2021-03-29 18:47 UTC (permalink / raw)
  To: Ajay.Kathat, dan.carpenter
  Cc: Claudiu.Beznea, kvalo, linux-wireless, kernel-janitors

On Fri, 2021-03-19 at 16:09 +0000, Ajay.Kathat@microchip.com wrote:
> On 19/03/21 8:17 pm, Dan Carpenter wrote:
> > If the loop fails, the "while(trials--) {" loop will exit with "trials"
> > set to -1.  The test for that expects it to end with "trials" set to 0
> > so the warning message will not be printed.
> > 
> > Fix this by changing from a post-op to a pre-op.  This does mean that
> > we only make 99 attempts instead of 100 but that's okay.
> > 
> > Fixes: f135a1571a05 ("wilc1000: Support chip sleep over SPI")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Thanks Dan.

Good catch, but wouldn't it be better to fix the time-out check
condition instead?  Something a long the lines of:

--- drivers/net/wireless/microchip/wilc1000/wlan.c~	2021-03-29 12:44:52.066039259 -0600
+++ drivers/net/wireless/microchip/wilc1000/wlan.c	2021-03-29 12:40:29.176365116 -0600
@@ -457,7 +457,7 @@
 	u32 wakeup_reg, wakeup_bit;
 	u32 to_host_from_fw_reg, to_host_from_fw_bit;
 	u32 from_host_to_fw_reg, from_host_to_fw_bit;
-	u32 trials = 100;
+	int trials = 100;
 	int ret;
 
 	if (wilc->io_type == WILC_HIF_SDIO) {
@@ -483,7 +483,7 @@
 		if ((reg & to_host_from_fw_bit) == 0)
 			break;
 	}
-	if (!trials)
+	if (trials < 0)
 		pr_warn("FW not responding\n");
 
 	/* Clear bit 1 */


This way, the loop could actually get executed the number of times
indicated by the initialization of "trial" before issuing a warning
message.

  --david

> Acked-by: Ajay Singh <ajay.kathat@microchip.com>
> 
> > ---
> >  drivers/net/wireless/microchip/wilc1000/wlan.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/wireless/microchip/wilc1000/wlan.c b/drivers/net/wireless/microchip/wilc1000/wlan.c
> > index d4a90c490084..2030fc7f53ca 100644
> > --- a/drivers/net/wireless/microchip/wilc1000/wlan.c
> > +++ b/drivers/net/wireless/microchip/wilc1000/wlan.c
> > @@ -575,7 +575,7 @@ void chip_allow_sleep(struct wilc *wilc)
> >                 to_host_from_fw_bit = WILC_SPI_FW_TO_HOST_BIT;
> >         }
> > 
> > -       while (trials--) {
> > +       while (--trials) {
> >                 ret = hif_func->hif_read_reg(wilc, to_host_from_fw_reg, &reg);
> >                 if (ret)
> >                         return;
> > --
> > 2.30.2
> > 


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

* Re: [PATCH] wilc1000: fix a loop timeout condition
  2021-03-29 18:47   ` David Mosberger-Tang
@ 2021-03-30  8:52     ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2021-03-30  8:52 UTC (permalink / raw)
  To: David Mosberger-Tang
  Cc: Ajay.Kathat, Claudiu.Beznea, kvalo, linux-wireless, kernel-janitors

On Mon, Mar 29, 2021 at 12:47:15PM -0600, David Mosberger-Tang wrote:
> On Fri, 2021-03-19 at 16:09 +0000, Ajay.Kathat@microchip.com wrote:
> > On 19/03/21 8:17 pm, Dan Carpenter wrote:
> > > If the loop fails, the "while(trials--) {" loop will exit with "trials"
> > > set to -1.  The test for that expects it to end with "trials" set to 0
> > > so the warning message will not be printed.
> > > 
> > > Fix this by changing from a post-op to a pre-op.  This does mean that
> > > we only make 99 attempts instead of 100 but that's okay.
> > > 
> > > Fixes: f135a1571a05 ("wilc1000: Support chip sleep over SPI")
> > > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > Thanks Dan.
> 
> Good catch, but wouldn't it be better to fix the time-out check
> condition instead?  Something a long the lines of:
> 
> --- drivers/net/wireless/microchip/wilc1000/wlan.c~	2021-03-29 12:44:52.066039259 -0600
> +++ drivers/net/wireless/microchip/wilc1000/wlan.c	2021-03-29 12:40:29.176365116 -0600
> @@ -457,7 +457,7 @@
>  	u32 wakeup_reg, wakeup_bit;
>  	u32 to_host_from_fw_reg, to_host_from_fw_bit;
>  	u32 from_host_to_fw_reg, from_host_to_fw_bit;
> -	u32 trials = 100;
> +	int trials = 100;
>  	int ret;
>  
>  	if (wilc->io_type == WILC_HIF_SDIO) {
> @@ -483,7 +483,7 @@
>  		if ((reg & to_host_from_fw_bit) == 0)
>  			break;
>  	}
> -	if (!trials)
> +	if (trials < 0)
>  		pr_warn("FW not responding\n");
>  
>  	/* Clear bit 1 */
> 
> 
> This way, the loop could actually get executed the number of times
> indicated by the initialization of "trial" before issuing a warning
> message.

Those numbers are just made up...  It doesn't matter either way.

regards,
dan carpenter


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

* Re: [PATCH] wilc1000: fix a loop timeout condition
  2021-03-19 14:47 [PATCH] wilc1000: fix a loop timeout condition Dan Carpenter
  2021-03-19 16:09 ` Ajay.Kathat
@ 2021-04-17 17:54 ` Kalle Valo
  1 sibling, 0 replies; 5+ messages in thread
From: Kalle Valo @ 2021-04-17 17:54 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Ajay Singh, Claudiu Beznea, David Mosberger-Tang, linux-wireless,
	kernel-janitors

Dan Carpenter <dan.carpenter@oracle.com> wrote:

> If the loop fails, the "while(trials--) {" loop will exit with "trials"
> set to -1.  The test for that expects it to end with "trials" set to 0
> so the warning message will not be printed.
> 
> Fix this by changing from a post-op to a pre-op.  This does mean that
> we only make 99 attempts instead of 100 but that's okay.
> 
> Fixes: f135a1571a05 ("wilc1000: Support chip sleep over SPI")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Acked-by: Ajay Singh <ajay.kathat@microchip.com>

Patch applied to wireless-drivers-next.git, thanks.

2f51061edab9 wilc1000: fix a loop timeout condition

-- 
https://patchwork.kernel.org/project/linux-wireless/patch/YFS5gx/gi70zlIaO@mwanda/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


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

end of thread, other threads:[~2021-04-17 17:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-19 14:47 [PATCH] wilc1000: fix a loop timeout condition Dan Carpenter
2021-03-19 16:09 ` Ajay.Kathat
2021-03-29 18:47   ` David Mosberger-Tang
2021-03-30  8:52     ` Dan Carpenter
2021-04-17 17:54 ` Kalle Valo

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