diff mbox

[5/10,v2] Input: cpcap-pwrbutton: Handle return value of platform_get_irq

Message ID ae8e2bcc48ceeb7cf04f4ec19e7cc76d51fcf58f.1510952504.git.arvind.yadav.cs@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Arvind Yadav Nov. 17, 2017, 9:06 p.m. UTC
platform_get_irq() can fail here and we must check its return value.

Signed-off-by: Arvind Yadav <arvind.yadav.cs@gmail.com>
---
changes in v2 :
              return irq instead of -ENODEV.

 drivers/input/misc/cpcap-pwrbutton.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Russell King (Oracle) Nov. 18, 2017, 8:21 a.m. UTC | #1
On Sat, Nov 18, 2017 at 02:36:53AM +0530, Arvind Yadav wrote:
> platform_get_irq() can fail here and we must check its return value.

The test should be <= 0, and you need to return an error code for the
0 case.
Dmitry Torokhov Nov. 18, 2017, 6:27 p.m. UTC | #2
On Sat, Nov 18, 2017 at 08:21:22AM +0000, Russell King - ARM Linux wrote:
> On Sat, Nov 18, 2017 at 02:36:53AM +0530, Arvind Yadav wrote:
> > platform_get_irq() can fail here and we must check its return value.
> 
> The test should be <= 0, and you need to return an error code for the
> 0 case.

Instead of polluting the drivers with special handling of 0 vs negative
error we should have platform_get_irq[_byname] return -EINVAL if it sees
0.

Thanks.
diff mbox

Patch

diff --git a/drivers/input/misc/cpcap-pwrbutton.c b/drivers/input/misc/cpcap-pwrbutton.c
index 0abef63..3a0626b 100644
--- a/drivers/input/misc/cpcap-pwrbutton.c
+++ b/drivers/input/misc/cpcap-pwrbutton.c
@@ -57,6 +57,9 @@  static int cpcap_power_button_probe(struct platform_device *pdev)
 	int irq = platform_get_irq(pdev, 0);
 	int err;
 
+	if (irq < 0)
+		return irq;
+
 	button = devm_kmalloc(&pdev->dev, sizeof(*button), GFP_KERNEL);
 	if (!button)
 		return -ENOMEM;