linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: dsa: b53: Replace mdelay with msleep in b53_switch_reset_gpio
@ 2018-04-11  1:51 Jia-Ju Bai
  2018-04-11  5:30 ` Phil Reid
  0 siblings, 1 reply; 5+ messages in thread
From: Jia-Ju Bai @ 2018-04-11  1:51 UTC (permalink / raw)
  To: f.fainelli, andrew, vivien.didelot; +Cc: netdev, linux-kernel, Jia-Ju Bai

b53_switch_reset_gpio() is never called in atomic context.

The call chain ending up at b53_switch_reset_gpio() is:
[1] b53_switch_reset_gpio() <- b53_switch_reset() <- 
	b53_reset_switch() <- b53_setup()

b53_switch_reset_gpio() is set as ".setup" in struct dsa_switch_ops.
This function is not called in atomic context.

Despite never getting called from atomic context, b53_switch_reset_gpio()
calls mdelay() to busily wait.
This is not necessary and can be replaced with msleep() to
avoid busy waiting.

This is found by a static analysis tool named DCNS written by myself.
And I also manually check it.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/net/dsa/b53/b53_common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index 274f367..e070ff6 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -597,10 +597,10 @@ static void b53_switch_reset_gpio(struct b53_device *dev)
 	/* Reset sequence: RESET low(50ms)->high(20ms)
 	 */
 	gpio_set_value(gpio, 0);
-	mdelay(50);
+	msleep(50);
 
 	gpio_set_value(gpio, 1);
-	mdelay(20);
+	msleep(20);
 
 	dev->current_page = 0xff;
 }
-- 
1.9.1

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

* Re: [PATCH] net: dsa: b53: Replace mdelay with msleep in b53_switch_reset_gpio
  2018-04-11  1:51 [PATCH] net: dsa: b53: Replace mdelay with msleep in b53_switch_reset_gpio Jia-Ju Bai
@ 2018-04-11  5:30 ` Phil Reid
  2018-04-11  7:14   ` Jia-Ju Bai
  0 siblings, 1 reply; 5+ messages in thread
From: Phil Reid @ 2018-04-11  5:30 UTC (permalink / raw)
  To: Jia-Ju Bai, f.fainelli, andrew, vivien.didelot; +Cc: netdev, linux-kernel

On 11/04/2018 09:51, Jia-Ju Bai wrote:
> b53_switch_reset_gpio() is never called in atomic context.
> 
> The call chain ending up at b53_switch_reset_gpio() is:
> [1] b53_switch_reset_gpio() <- b53_switch_reset() <-
> 	b53_reset_switch() <- b53_setup()
> 
> b53_switch_reset_gpio() is set as ".setup" in struct dsa_switch_ops.
> This function is not called in atomic context.
> 
> Despite never getting called from atomic context, b53_switch_reset_gpio()
> calls mdelay() to busily wait.
> This is not necessary and can be replaced with msleep() to
> avoid busy waiting.
> 
> This is found by a static analysis tool named DCNS written by myself.
> And I also manually check it.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>   drivers/net/dsa/b53/b53_common.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
> index 274f367..e070ff6 100644
> --- a/drivers/net/dsa/b53/b53_common.c
> +++ b/drivers/net/dsa/b53/b53_common.c
> @@ -597,10 +597,10 @@ static void b53_switch_reset_gpio(struct b53_device *dev)
>   	/* Reset sequence: RESET low(50ms)->high(20ms)
>   	 */
>   	gpio_set_value(gpio, 0);
> -	mdelay(50);
> +	msleep(50);
>   
>   	gpio_set_value(gpio, 1);
> -	mdelay(20);
> +	msleep(20);
>   
>   	dev->current_page = 0xff;
>   }
> 
Would that also imply gpio_set_value could be gpio_set_value_cansleep?


-- 
Regards
Phil Reid

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

* Re: [PATCH] net: dsa: b53: Replace mdelay with msleep in b53_switch_reset_gpio
  2018-04-11  5:30 ` Phil Reid
@ 2018-04-11  7:14   ` Jia-Ju Bai
  2018-04-11 16:19     ` Florian Fainelli
  0 siblings, 1 reply; 5+ messages in thread
From: Jia-Ju Bai @ 2018-04-11  7:14 UTC (permalink / raw)
  To: Phil Reid, f.fainelli, andrew, vivien.didelot; +Cc: netdev, linux-kernel



On 2018/4/11 13:30, Phil Reid wrote:
> On 11/04/2018 09:51, Jia-Ju Bai wrote:
>> b53_switch_reset_gpio() is never called in atomic context.
>>
>> The call chain ending up at b53_switch_reset_gpio() is:
>> [1] b53_switch_reset_gpio() <- b53_switch_reset() <-
>>     b53_reset_switch() <- b53_setup()
>>
>> b53_switch_reset_gpio() is set as ".setup" in struct dsa_switch_ops.
>> This function is not called in atomic context.
>>
>> Despite never getting called from atomic context, 
>> b53_switch_reset_gpio()
>> calls mdelay() to busily wait.
>> This is not necessary and can be replaced with msleep() to
>> avoid busy waiting.
>>
>> This is found by a static analysis tool named DCNS written by myself.
>> And I also manually check it.
>>
>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>> ---
>>   drivers/net/dsa/b53/b53_common.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/dsa/b53/b53_common.c 
>> b/drivers/net/dsa/b53/b53_common.c
>> index 274f367..e070ff6 100644
>> --- a/drivers/net/dsa/b53/b53_common.c
>> +++ b/drivers/net/dsa/b53/b53_common.c
>> @@ -597,10 +597,10 @@ static void b53_switch_reset_gpio(struct 
>> b53_device *dev)
>>       /* Reset sequence: RESET low(50ms)->high(20ms)
>>        */
>>       gpio_set_value(gpio, 0);
>> -    mdelay(50);
>> +    msleep(50);
>>         gpio_set_value(gpio, 1);
>> -    mdelay(20);
>> +    msleep(20);
>>         dev->current_page = 0xff;
>>   }
>>
> Would that also imply gpio_set_value could be gpio_set_value_cansleep?
>

Yes, I think gpio_set_value_cansleep() is okay here?
Do I need to send a V2 patch to replace gpio_set_value()?


Best wishes,
Jia-Ju Bai

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

* Re: [PATCH] net: dsa: b53: Replace mdelay with msleep in b53_switch_reset_gpio
  2018-04-11  7:14   ` Jia-Ju Bai
@ 2018-04-11 16:19     ` Florian Fainelli
  2018-04-12  1:49       ` Jia-Ju Bai
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Fainelli @ 2018-04-11 16:19 UTC (permalink / raw)
  To: Jia-Ju Bai, Phil Reid, andrew, vivien.didelot; +Cc: netdev, linux-kernel

On 04/11/2018 12:14 AM, Jia-Ju Bai wrote:
> 
> 
> On 2018/4/11 13:30, Phil Reid wrote:
>> On 11/04/2018 09:51, Jia-Ju Bai wrote:
>>> b53_switch_reset_gpio() is never called in atomic context.
>>>
>>> The call chain ending up at b53_switch_reset_gpio() is:
>>> [1] b53_switch_reset_gpio() <- b53_switch_reset() <-
>>>     b53_reset_switch() <- b53_setup()
>>>
>>> b53_switch_reset_gpio() is set as ".setup" in struct dsa_switch_ops.
>>> This function is not called in atomic context.
>>>
>>> Despite never getting called from atomic context,
>>> b53_switch_reset_gpio()
>>> calls mdelay() to busily wait.
>>> This is not necessary and can be replaced with msleep() to
>>> avoid busy waiting.
>>>
>>> This is found by a static analysis tool named DCNS written by myself.
>>> And I also manually check it.
>>>
>>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>>> ---
>>>   drivers/net/dsa/b53/b53_common.c | 4 ++--
>>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/net/dsa/b53/b53_common.c
>>> b/drivers/net/dsa/b53/b53_common.c
>>> index 274f367..e070ff6 100644
>>> --- a/drivers/net/dsa/b53/b53_common.c
>>> +++ b/drivers/net/dsa/b53/b53_common.c
>>> @@ -597,10 +597,10 @@ static void b53_switch_reset_gpio(struct
>>> b53_device *dev)
>>>       /* Reset sequence: RESET low(50ms)->high(20ms)
>>>        */
>>>       gpio_set_value(gpio, 0);
>>> -    mdelay(50);
>>> +    msleep(50);
>>>         gpio_set_value(gpio, 1);
>>> -    mdelay(20);
>>> +    msleep(20);
>>>         dev->current_page = 0xff;
>>>   }
>>>
>> Would that also imply gpio_set_value could be gpio_set_value_cansleep?
>>
> 
> Yes, I think gpio_set_value_cansleep() is okay here?
> Do I need to send a V2 patch to replace gpio_set_value()?

Yes, I would lump these two changes in the same patch since this is
effectively about solving sleeping vs. non sleeping operations.

Thanks!
-- 
Florian

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

* Re: [PATCH] net: dsa: b53: Replace mdelay with msleep in b53_switch_reset_gpio
  2018-04-11 16:19     ` Florian Fainelli
@ 2018-04-12  1:49       ` Jia-Ju Bai
  0 siblings, 0 replies; 5+ messages in thread
From: Jia-Ju Bai @ 2018-04-12  1:49 UTC (permalink / raw)
  To: Florian Fainelli, Phil Reid, andrew, vivien.didelot; +Cc: netdev, linux-kernel



On 2018/4/12 0:19, Florian Fainelli wrote:
> On 04/11/2018 12:14 AM, Jia-Ju Bai wrote:
>>
>> On 2018/4/11 13:30, Phil Reid wrote:
>>> On 11/04/2018 09:51, Jia-Ju Bai wrote:
>>>> b53_switch_reset_gpio() is never called in atomic context.
>>>>
>>>> The call chain ending up at b53_switch_reset_gpio() is:
>>>> [1] b53_switch_reset_gpio() <- b53_switch_reset() <-
>>>>      b53_reset_switch() <- b53_setup()
>>>>
>>>> b53_switch_reset_gpio() is set as ".setup" in struct dsa_switch_ops.
>>>> This function is not called in atomic context.
>>>>
>>>> Despite never getting called from atomic context,
>>>> b53_switch_reset_gpio()
>>>> calls mdelay() to busily wait.
>>>> This is not necessary and can be replaced with msleep() to
>>>> avoid busy waiting.
>>>>
>>>> This is found by a static analysis tool named DCNS written by myself.
>>>> And I also manually check it.
>>>>
>>>> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
>>>> ---
>>>>    drivers/net/dsa/b53/b53_common.c | 4 ++--
>>>>    1 file changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/drivers/net/dsa/b53/b53_common.c
>>>> b/drivers/net/dsa/b53/b53_common.c
>>>> index 274f367..e070ff6 100644
>>>> --- a/drivers/net/dsa/b53/b53_common.c
>>>> +++ b/drivers/net/dsa/b53/b53_common.c
>>>> @@ -597,10 +597,10 @@ static void b53_switch_reset_gpio(struct
>>>> b53_device *dev)
>>>>        /* Reset sequence: RESET low(50ms)->high(20ms)
>>>>         */
>>>>        gpio_set_value(gpio, 0);
>>>> -    mdelay(50);
>>>> +    msleep(50);
>>>>          gpio_set_value(gpio, 1);
>>>> -    mdelay(20);
>>>> +    msleep(20);
>>>>          dev->current_page = 0xff;
>>>>    }
>>>>
>>> Would that also imply gpio_set_value could be gpio_set_value_cansleep?
>>>
>> Yes, I think gpio_set_value_cansleep() is okay here?
>> Do I need to send a V2 patch to replace gpio_set_value()?
> Yes, I would lump these two changes in the same patch since this is
> effectively about solving sleeping vs. non sleeping operations.

Okay, I have sent a V2 patch, and you can have a look :)


Best wishes,
Jia-Ju Bai

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

end of thread, other threads:[~2018-04-12  1:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-11  1:51 [PATCH] net: dsa: b53: Replace mdelay with msleep in b53_switch_reset_gpio Jia-Ju Bai
2018-04-11  5:30 ` Phil Reid
2018-04-11  7:14   ` Jia-Ju Bai
2018-04-11 16:19     ` Florian Fainelli
2018-04-12  1:49       ` Jia-Ju Bai

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