linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ipmi:bt-bmc: Fix error handling and status check
@ 2020-04-18  8:02 Tang Bin
  2020-04-18 13:49 ` Corey Minyard
  0 siblings, 1 reply; 5+ messages in thread
From: Tang Bin @ 2020-04-18  8:02 UTC (permalink / raw)
  To: minyard, arnd, gregkh
  Cc: openipmi-developer, linux-kernel, Tang Bin, Shengju Zhang

If the function platform_get_irq() failed, the negative
value returned will not be detected here. So fix error
handling in bt_bmc_config_irq(). And if devm_request_irq()
failed, 'bt_bmc->irq' is assigned to zero maybe redundant,
it may be more suitable for using the correct negative values
to make the status check in the function bt_bmc_remove().

Signed-off-by: Shengju Zhang <zhangshengju@cmss.chinamobile.com>
Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
---
Changes from v1
 - fix the code of status check
---
 drivers/char/ipmi/bt-bmc.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/char/ipmi/bt-bmc.c b/drivers/char/ipmi/bt-bmc.c
index cd0349bff..33d3a5d50 100644
--- a/drivers/char/ipmi/bt-bmc.c
+++ b/drivers/char/ipmi/bt-bmc.c
@@ -399,15 +399,14 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
 	struct device *dev = &pdev->dev;
 	int rc;
 
-	bt_bmc->irq = platform_get_irq(pdev, 0);
-	if (!bt_bmc->irq)
-		return -ENODEV;
+	bt_bmc->irq = platform_get_irq_optional(pdev, 0);
+	if (bt_bmc->irq < 0)
+		return bt_bmc->irq;
 
 	rc = devm_request_irq(dev, bt_bmc->irq, bt_bmc_irq, IRQF_SHARED,
 			      DEVICE_NAME, bt_bmc);
 	if (rc < 0) {
 		dev_warn(dev, "Unable to request IRQ %d\n", bt_bmc->irq);
-		bt_bmc->irq = 0;
 		return rc;
 	}
 
@@ -474,7 +473,7 @@ static int bt_bmc_probe(struct platform_device *pdev)
 
 	bt_bmc_config_irq(bt_bmc, pdev);
 
-	if (bt_bmc->irq) {
+	if (bt_bmc->irq >= 0) {
 		dev_info(dev, "Using IRQ %d\n", bt_bmc->irq);
 	} else {
 		dev_info(dev, "No IRQ; using timer\n");
@@ -500,7 +499,7 @@ static int bt_bmc_remove(struct platform_device *pdev)
 	struct bt_bmc *bt_bmc = dev_get_drvdata(&pdev->dev);
 
 	misc_deregister(&bt_bmc->miscdev);
-	if (!bt_bmc->irq)
+	if (bt_bmc->irq < 0)
 		del_timer_sync(&bt_bmc->poll_timer);
 	return 0;
 }
-- 
2.20.1.windows.1




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

* Re: [PATCH v2] ipmi:bt-bmc: Fix error handling and status check
  2020-04-18  8:02 [PATCH v2] ipmi:bt-bmc: Fix error handling and status check Tang Bin
@ 2020-04-18 13:49 ` Corey Minyard
  2020-04-19  6:29   ` Tang Bin
  0 siblings, 1 reply; 5+ messages in thread
From: Corey Minyard @ 2020-04-18 13:49 UTC (permalink / raw)
  To: Tang Bin; +Cc: arnd, gregkh, openipmi-developer, linux-kernel, Shengju Zhang

On Sat, Apr 18, 2020 at 04:02:29PM +0800, Tang Bin wrote:
> If the function platform_get_irq() failed, the negative
> value returned will not be detected here. So fix error
> handling in bt_bmc_config_irq(). And if devm_request_irq()
> failed, 'bt_bmc->irq' is assigned to zero maybe redundant,
> it may be more suitable for using the correct negative values
> to make the status check in the function bt_bmc_remove().

You need to mention changing platform_get_irq to
platform_get_irq_optional in the header.

Another comment inline below.

Otherwise, this looks good.

> 
> Signed-off-by: Shengju Zhang <zhangshengju@cmss.chinamobile.com>
> Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
> ---
> Changes from v1
>  - fix the code of status check
> ---
>  drivers/char/ipmi/bt-bmc.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/char/ipmi/bt-bmc.c b/drivers/char/ipmi/bt-bmc.c
> index cd0349bff..33d3a5d50 100644
> --- a/drivers/char/ipmi/bt-bmc.c
> +++ b/drivers/char/ipmi/bt-bmc.c
> @@ -399,15 +399,14 @@ static int bt_bmc_config_irq(struct bt_bmc *bt_bmc,
>  	struct device *dev = &pdev->dev;
>  	int rc;
>  
> -	bt_bmc->irq = platform_get_irq(pdev, 0);
> -	if (!bt_bmc->irq)
> -		return -ENODEV;
> +	bt_bmc->irq = platform_get_irq_optional(pdev, 0);
> +	if (bt_bmc->irq < 0)
> +		return bt_bmc->irq;
>  
>  	rc = devm_request_irq(dev, bt_bmc->irq, bt_bmc_irq, IRQF_SHARED,
>  			      DEVICE_NAME, bt_bmc);
>  	if (rc < 0) {
>  		dev_warn(dev, "Unable to request IRQ %d\n", bt_bmc->irq);
> -		bt_bmc->irq = 0;

You need to set this to rc.  Otherwise it will remain the interrupt
number assigned by platform_get_irq_optional().

-corey

>  		return rc;
>  	}
>  
> @@ -474,7 +473,7 @@ static int bt_bmc_probe(struct platform_device *pdev)
>  
>  	bt_bmc_config_irq(bt_bmc, pdev);
>  
> -	if (bt_bmc->irq) {
> +	if (bt_bmc->irq >= 0) {
>  		dev_info(dev, "Using IRQ %d\n", bt_bmc->irq);
>  	} else {
>  		dev_info(dev, "No IRQ; using timer\n");
> @@ -500,7 +499,7 @@ static int bt_bmc_remove(struct platform_device *pdev)
>  	struct bt_bmc *bt_bmc = dev_get_drvdata(&pdev->dev);
>  
>  	misc_deregister(&bt_bmc->miscdev);
> -	if (!bt_bmc->irq)
> +	if (bt_bmc->irq < 0)
>  		del_timer_sync(&bt_bmc->poll_timer);
>  	return 0;
>  }
> -- 
> 2.20.1.windows.1
> 
> 
> 

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

* Re: [PATCH v2] ipmi:bt-bmc: Fix error handling and status check
  2020-04-18 13:49 ` Corey Minyard
@ 2020-04-19  6:29   ` Tang Bin
  2020-05-04  7:43     ` Tang Bin
  2020-05-04 13:16     ` Corey Minyard
  0 siblings, 2 replies; 5+ messages in thread
From: Tang Bin @ 2020-04-19  6:29 UTC (permalink / raw)
  To: minyard; +Cc: arnd, gregkh, openipmi-developer, linux-kernel

Hi, Corey:

On 2020/4/18 21:49, Corey Minyard wrote:
> On Sat, Apr 18, 2020 at 04:02:29PM +0800, Tang Bin wrote:
>> If the function platform_get_irq() failed, the negative
>> value returned will not be detected here. So fix error
>> handling in bt_bmc_config_irq(). And if devm_request_irq()
>> failed, 'bt_bmc->irq' is assigned to zero maybe redundant,
>> it may be more suitable for using the correct negative values
>> to make the status check in the function bt_bmc_remove().
> You need to mention changing platform_get_irq to
> platform_get_irq_optional in the header.
>
> Another comment inline below.
>
> Otherwise, this looks good.

Got it. The v3 will be as follows:

If the function platform_get_irq() failed, the negative value

returned will not be detected here. So fix error handling in

bt_bmc_config_irq(). And in the function bt_bmc_probe(),

when get irq failed, it will print error message. So use

platform_get_irq_optional() to simplify code. Finally in the

function bt_bmc_remove() should make the right status

check if get irq failed.

>
> You need to set this to rc.  Otherwise it will remain the interrupt
> number assigned by platform_get_irq_optional().

Yes, I think you are right. I'm not as considerate as you. Thank you for 
your instruction.

When get irq failed, the 'bt_bmc->irq' is negative; when request irq 
failed, the 'bt_bmc->irq = 0' is right.

So 'bt_bmc->irq <= 0' means irq failed.

Now let me rearrange the logic here:

     In bt_bmc_probe():

         bt_bmc_config_irq(bt_bmc, pdev);

         if (bt_bmc->irq > 0) {

         }


     In bt_bmc_remove():

         if (bt_bmc->irq <= 0)
             del_timer_sync(&bt_bmc->poll_timer);


If you think this logic is correct, I'll submit v3.

Thanks,

Tang Bin

>
>
>
>



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

* Re: [PATCH v2] ipmi:bt-bmc: Fix error handling and status check
  2020-04-19  6:29   ` Tang Bin
@ 2020-05-04  7:43     ` Tang Bin
  2020-05-04 13:16     ` Corey Minyard
  1 sibling, 0 replies; 5+ messages in thread
From: Tang Bin @ 2020-05-04  7:43 UTC (permalink / raw)
  To: minyard; +Cc: arnd, gregkh, openipmi-developer, linux-kernel

Hi, Corey:

On 2020/4/19 14:29, Tang Bin wrote:
> Hi, Corey:
>
> On 2020/4/18 21:49, Corey Minyard wrote:
>> On Sat, Apr 18, 2020 at 04:02:29PM +0800, Tang Bin wrote:
>>> If the function platform_get_irq() failed, the negative
>>> value returned will not be detected here. So fix error
>>> handling in bt_bmc_config_irq(). And if devm_request_irq()
>>> failed, 'bt_bmc->irq' is assigned to zero maybe redundant,
>>> it may be more suitable for using the correct negative values
>>> to make the status check in the function bt_bmc_remove().
>> You need to mention changing platform_get_irq to
>> platform_get_irq_optional in the header.
>>
>> Another comment inline below.
>>
>> Otherwise, this looks good.
>
> Got it. The v3 will be as follows:
>
> If the function platform_get_irq() failed, the negative value
>
> returned will not be detected here. So fix error handling in
>
> bt_bmc_config_irq(). And in the function bt_bmc_probe(),
>
> when get irq failed, it will print error message. So use
>
> platform_get_irq_optional() to simplify code. Finally in the
>
> function bt_bmc_remove() should make the right status
>
> check if get irq failed.
>
>>
>> You need to set this to rc.  Otherwise it will remain the interrupt
>> number assigned by platform_get_irq_optional().
>
> Yes, I think you are right. I'm not as considerate as you. Thank you 
> for your instruction.
>
> When get irq failed, the 'bt_bmc->irq' is negative; when request irq 
> failed, the 'bt_bmc->irq = 0' is right.
>
> So 'bt_bmc->irq <= 0' means irq failed.
>
> Now let me rearrange the logic here:
>
>     In bt_bmc_probe():
>
>         bt_bmc_config_irq(bt_bmc, pdev);
>
>         if (bt_bmc->irq > 0) {
>
>         }
>
>
>     In bt_bmc_remove():
>
>         if (bt_bmc->irq <= 0)
>             del_timer_sync(&bt_bmc->poll_timer);
>
>
> If you think this logic is correct, I'll submit v3.
>
>
>
I know you're very busy, and you have handed me a lot before, so I 
should wait for your reply.

But I don't know whether my above logic is correct, so I take the 
liberty to write this email to you. I just wanted to say sorry for 
disturbing you.

Thanks,

Tang Bin









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

* Re: [PATCH v2] ipmi:bt-bmc: Fix error handling and status check
  2020-04-19  6:29   ` Tang Bin
  2020-05-04  7:43     ` Tang Bin
@ 2020-05-04 13:16     ` Corey Minyard
  1 sibling, 0 replies; 5+ messages in thread
From: Corey Minyard @ 2020-05-04 13:16 UTC (permalink / raw)
  To: Tang Bin; +Cc: arnd, gregkh, openipmi-developer, linux-kernel

On Sun, Apr 19, 2020 at 02:29:26PM +0800, Tang Bin wrote:
> Hi, Corey:
> 
> On 2020/4/18 21:49, Corey Minyard wrote:
> > On Sat, Apr 18, 2020 at 04:02:29PM +0800, Tang Bin wrote:
> > > If the function platform_get_irq() failed, the negative
> > > value returned will not be detected here. So fix error
> > > handling in bt_bmc_config_irq(). And if devm_request_irq()
> > > failed, 'bt_bmc->irq' is assigned to zero maybe redundant,
> > > it may be more suitable for using the correct negative values
> > > to make the status check in the function bt_bmc_remove().
> > You need to mention changing platform_get_irq to
> > platform_get_irq_optional in the header.
> > 
> > Another comment inline below.
> > 
> > Otherwise, this looks good.
> 
> Got it. The v3 will be as follows:
> 
> If the function platform_get_irq() failed, the negative value
> 
> returned will not be detected here. So fix error handling in
> 
> bt_bmc_config_irq(). And in the function bt_bmc_probe(),
> 
> when get irq failed, it will print error message. So use
> 
> platform_get_irq_optional() to simplify code. Finally in the
> 
> function bt_bmc_remove() should make the right status
> 
> check if get irq failed.
> 
> > 
> > You need to set this to rc.  Otherwise it will remain the interrupt
> > number assigned by platform_get_irq_optional().
> 
> Yes, I think you are right. I'm not as considerate as you. Thank you for
> your instruction.
> 
> When get irq failed, the 'bt_bmc->irq' is negative; when request irq failed,
> the 'bt_bmc->irq = 0' is right.
> 
> So 'bt_bmc->irq <= 0' means irq failed.

Sorry, I missed your question here and was waiting for v3.

Well, we want bt_bmc->irq < 0 to mean the irq request failed.

> 
> Now let me rearrange the logic here:
> 
>     In bt_bmc_probe():
> 
>         bt_bmc_config_irq(bt_bmc, pdev);
> 
>         if (bt_bmc->irq > 0) {

Should be >= 0.

> 
>         }
> 
> 
>     In bt_bmc_remove():
> 
>         if (bt_bmc->irq <= 0)
>             del_timer_sync(&bt_bmc->poll_timer);

Should be < 0.  But other than that, I think it's correct.

-corey

> 
> 
> If you think this logic is correct, I'll submit v3.
> 
> Thanks,
> 
> Tang Bin
> 
> > 
> > 
> > 
> > 
> 
> 

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

end of thread, other threads:[~2020-05-04 13:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-18  8:02 [PATCH v2] ipmi:bt-bmc: Fix error handling and status check Tang Bin
2020-04-18 13:49 ` Corey Minyard
2020-04-19  6:29   ` Tang Bin
2020-05-04  7:43     ` Tang Bin
2020-05-04 13:16     ` Corey Minyard

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