Skip to contentSkip to conversation

Input: ep93xx_keypad - Fix handling of platform_get_irq() error

PATCH In review Krzysztof Kozlowski 3 participants 14 messages Aug 28, 2020 – Sep 16, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 Input: ep93xx_keypad - Fix handling of platform_get_irq() error

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Fixes 60214f058f44 ("Input: ep93xx_keypad - update driver to new core support")

---

Changes since v1:
1. None

---
 drivers/input/keyboard/ep93xx_keypad.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/input/keyboard/ep93xx_keypad.c +2 -2
index 7c70492d9d6b..f831f01501d5 100644
@@ -250,8 +250,8 @@ static int ep93xx_keypad_probe(struct platform_device *pdev)
 	}
 
 	keypad->irq = platform_get_irq(pdev, 0);
-	if (!keypad->irq) {
-		err = -ENXIO;
+	if (keypad->irq < 0) {
+		err = keypad->irq;
 		goto failed_free;
 	}
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 2/4 Input: omap4-keypad - Fix handling of platform_get_irq() error

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Fixes f3a1ba60dbdb ("Input: omap4-keypad - use platform device helpers")

---

Changes since v1:
1. None

---
 drivers/input/keyboard/omap4-keypad.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/input/keyboard/omap4-keypad.c +2 -4
index 94c94d7f5155..b075f1af0305 100644
@@ -240,10 +240,8 @@ static int omap4_keypad_probe(struct platform_device *pdev)
 	}
 
 	irq = platform_get_irq(pdev, 0);
-	if (!irq) {
-		dev_err(&pdev->dev, "no keyboard irq assigned\n");
-		return -EINVAL;
-	}
+	if (irq < 0)
+		return -irq;
 
 	keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
 	if (!keypad_data) {
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH v2 2/4] Input: omap4-keypad - Fix handling of platform_get_irq() error

Quoted 19 lines · Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Fixes f3a1ba60dbdb ("Input: omap4-keypad - use platform device helpers")

---

Changes since v1:
1. None

---
 drivers/input/keyboard/omap4-keypad.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/input/keyboard/omap4-keypad.c +0 -0
index 94c94d7f5155..b075f1af0305 100644

drivers/input/keyboard/omap4-keypad.c static int omap4_keypad_probe(struct platform_device *pdev) · line 244

Quoted 9 lines
drivers/input/keyboard/omap4-keypad.c +2 -4
@@ -240,10 +240,8 @@ static int omap4_keypad_probe(struct platform_device *pdev)
 	}
 
 	irq = platform_get_irq(pdev, 0);
-	if (!irq) {
-		dev_err(&pdev->dev, "no keyboard irq assigned\n");
-		return -EINVAL;
-	}
+	if (irq < 0)
+		return -irq;

You must have meant just "irq", right?

Quoted 6 lines
drivers/input/keyboard/omap4-keypad.c +0 -0
 	keypad_data = kzalloc(sizeof(struct omap4_keypad), GFP_KERNEL);
 	if (!keypad_data) {
Signature · 1 line
2.17.1
Signature · 1 line
Dmitry
#3 lore raw

Re: [PATCH v2 2/4] Input: omap4-keypad - Fix handling of platform_get_irq() error

Quoted 23 lines · Dmitry Torokhov
Quoted 21 lines · Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Fixes f3a1ba60dbdb ("Input: omap4-keypad - use platform device helpers")

---

Changes since v1:
1. None

---
 drivers/input/keyboard/omap4-keypad.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/input/keyboard/omap4-keypad.c +0 -0
index 94c94d7f5155..b075f1af0305 100644
@@ -240,10 +240,8 @@ static int omap4_keypad_probe(struct platform_device *pdev)
      }
 
Quoted 9 lines

drivers/input/keyboard/omap4-keypad.c static int omap4_keypad_probe(struct platform_device *pdev) · line 244

Quoted 7 lines
drivers/input/keyboard/omap4-keypad.c +2 -4
      irq = platform_get_irq(pdev, 0);
-     if (!irq) {
-             dev_err(&pdev->dev, "no keyboard irq assigned\n");
-             return -EINVAL;
-     }
+     if (irq < 0)
+             return -irq;

You must have meant just "irq", right?

Damn it, of course. I'll send a v2 for this.

Best regards,
Krzysztof

maintainer
#4 lore raw

Re: [PATCH v2 2/4] Input: omap4-keypad - Fix handling of platform_get_irq() error

Quoted 35 lines · Krzysztof Kozlowski
Quoted 23 lines · Dmitry Torokhov
Quoted 21 lines · Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Fixes f3a1ba60dbdb ("Input: omap4-keypad - use platform device helpers")

---

Changes since v1:
1. None

---
 drivers/input/keyboard/omap4-keypad.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/input/keyboard/omap4-keypad.c +0 -0
index 94c94d7f5155..b075f1af0305 100644
@@ -240,10 +240,8 @@ static int omap4_keypad_probe(struct platform_device *pdev)
      }
 
Quoted 9 lines

drivers/input/keyboard/omap4-keypad.c static int omap4_keypad_probe(struct platform_device *pdev) · line 244

Quoted 7 lines
drivers/input/keyboard/omap4-keypad.c +2 -4
      irq = platform_get_irq(pdev, 0);
-     if (!irq) {
-             dev_err(&pdev->dev, "no keyboard irq assigned\n");
-             return -EINVAL;
-     }
+     if (irq < 0)
+             return -irq;

You must have meant just "irq", right?

Quoted 1 line

Damn it, of course. I'll send a v2 for this.

It's fine, I can fix it up locally.

Thanks.

Signature · 1 line
Dmitry
#5 lore raw

PATCH v2 3/4 Input: twl4030_keypad - Fix handling of platform_get_irq() error

In reply to Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case casting to unsigned and comparing to 0 would pass the check.

Fixes 7abf38d6d13c ("Input: twl4030-keypad - add device tree support")

---

Changes since v1:
1. Fix also casting return value to unsigned.

---
 drivers/input/keyboard/twl4030_keypad.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/input/keyboard/twl4030_keypad.c +3 -5
index af3a6824f1a4..77e0743a3cf8 100644
@@ -50,7 +50,7 @@ struct twl4030_keypad {
 	bool		autorepeat;
 	unsigned int	n_rows;
 	unsigned int	n_cols;
-	unsigned int	irq;
+	int		irq;
 
 	struct device *dbg_dev;
 	struct input_dev *input;
@@ -376,10 +376,8 @@ static int twl4030_kp_probe(struct platform_device *pdev)
 	}
 
 	kp->irq = platform_get_irq(pdev, 0);
-	if (!kp->irq) {
-		dev_err(&pdev->dev, "no keyboard irq assigned\n");
-		return -EINVAL;
-	}
+	if (kp->irq < 0)
+		return kp->irq;
 
 	error = matrix_keypad_build_keymap(keymap_data, NULL,
 					   TWL4030_MAX_ROWS,
Signature · 1 line
2.17.1
#6 lore raw

PATCH v2 4/4 Input: sun4i-ps2 - Fix handling of platform_get_irq() error

In reply to Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Fixes e443631d20f5 ("Input: serio - add support for Alwinner A10/A20 PS/2 controller")

---

Changes since v1:
1. None

---
 drivers/input/serio/sun4i-ps2.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/input/serio/sun4i-ps2.c +2 -3
index a681a2c04e39..7da1ea8741fc 100644
@@ -265,9 +265,8 @@ static int sun4i_ps2_probe(struct platform_device *pdev)
 
 	/* Get IRQ for the device */
 	irq = platform_get_irq(pdev, 0);
-	if (!irq) {
-		dev_err(dev, "no IRQ found\n");
-		error = -ENXIO;
+	if (irq < 0) {
+		error = irq;
 		goto err_disable_clk;
 	}
 
Signature · 1 line
2.17.1
maintainer
#8 lore raw

Re: [PATCH v2 4/4] Input: sun4i-ps2 - Fix handling of platform_get_irq() error

In reply to Krzysztof Kozlowski
Quoted 19 lines · Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Fixes e443631d20f5 ("Input: serio - add support for Alwinner A10/A20 PS/2 controller")

---

Changes since v1:
1. None

---
 drivers/input/serio/sun4i-ps2.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/input/serio/sun4i-ps2.c +0 -0
index a681a2c04e39..7da1ea8741fc 100644

drivers/input/serio/sun4i-ps2.c static int sun4i_ps2_probe(struct platform_device *pdev) · line 268

Quoted 7 lines
drivers/input/serio/sun4i-ps2.c +1 -3
@@ -265,9 +265,8 @@ static int sun4i_ps2_probe(struct platform_device *pdev)
 
 	/* Get IRQ for the device */
 	irq = platform_get_irq(pdev, 0);
-	if (!irq) {
-		dev_err(dev, "no IRQ found\n");
-		error = -ENXIO;
+	if (irq < 0) {

"irq" is unsigned here, so this will not work. I'll change it to use drvdat->irq which happens to be signed, and drop "irq" variable.

Quoted 7 lines
drivers/input/serio/sun4i-ps2.c +1 -0
+		error = irq;
 		goto err_disable_clk;
 	}
 
Signature · 1 line
2.17.1

Thanks.

Signature · 1 line
Dmitry
#9 lore raw

Re: [PATCH v2 4/4] Input: sun4i-ps2 - Fix handling of platform_get_irq() error

Quoted 22 lines · Dmitry Torokhov
Quoted 20 lines · Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Fixes e443631d20f5 ("Input: serio - add support for Alwinner A10/A20 PS/2 controller")

---

Changes since v1:
1. None

---
 drivers/input/serio/sun4i-ps2.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/input/serio/sun4i-ps2.c +0 -0
index a681a2c04e39..7da1ea8741fc 100644
@@ -265,9 +265,8 @@ static int sun4i_ps2_probe(struct platform_device *pdev)
 
Quoted 9 lines

drivers/input/serio/sun4i-ps2.c static int sun4i_ps2_probe(struct platform_device *pdev) · line 268

Quoted 6 lines
drivers/input/serio/sun4i-ps2.c +1 -3
      /* Get IRQ for the device */
      irq = platform_get_irq(pdev, 0);
-     if (!irq) {
-             dev_err(dev, "no IRQ found\n");
-             error = -ENXIO;
+     if (irq < 0) {

"irq" is unsigned here, so this will not work. I'll change it to use drvdat->irq which happens to be signed, and drop "irq" variable.

Yes, thanks. I wonder now why there was no warning of unsigned<0 comparison.

Best regards,
Krzysztof

#10 lore raw
In reply to Krzysztof Kozlowski
Quoted 6 lines · Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Fixes 60214f058f44 ("Input: ep93xx_keypad - update driver to new core support")
Quoted 7 lines

---

Changes since v1:
1. None

---
 drivers/input/keyboard/ep93xx_keypad.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Hi Dmitry,

Any comments on the series?

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#11 lore raw
In reply to Krzysztof Kozlowski

Hi Krzysztof,

Quoted 2 lines · Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

platform_get_irq() is a bit of a mess. Historically we allowed defining interrupt resource with r->start == 0 and for such cases non-OF non-ACPI code will return 0 from platform_get_irq() to indicate that IRQ is not assigned.

We either need to stop doing this in platform_get_irq(), or the conditions in this patch and followups should be "irq <= 0" and we need to make sure we do not accidentally return 0 from probe ...

Thanks.

Signature · 1 line
Dmitry
#12 lore raw
Quoted 7 lines · Dmitry Torokhov

Hi Krzysztof,

Quoted 2 lines · Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Quoted 8 lines

platform_get_irq() is a bit of a mess. Historically we allowed defining interrupt resource with r->start == 0 and for such cases non-OF non-ACPI code will return 0 from platform_get_irq() to indicate that IRQ is not assigned.

We either need to stop doing this in platform_get_irq(), or the conditions in this patch and followups should be "irq <= 0" and we need to make sure we do not accidentally return 0 from probe ...

Hi,

It's then contradictory to platform_get_irq documentation which explicitly says - zero will not be returned on error. This was also clarified in commit e330b9a6bb35 ("platform: don't return 0 from platform_get_irq[_byname]() on error").

As I understood the input drivers code, they check for errors so the coe in my patch is correct. Any "<=0" is not correct with current documentation and implementation.

Best regards,
Krzysztof

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#13 lore raw
Quoted 17 lines · Krzysztof Kozlowski
Quoted 7 lines · Dmitry Torokhov

Hi Krzysztof,

Quoted 2 lines · Krzysztof Kozlowski

platform_get_irq() returns -ERRNO on error. In such case comparison to 0 would pass the check.

Quoted 8 lines

platform_get_irq() is a bit of a mess. Historically we allowed defining interrupt resource with r->start == 0 and for such cases non-OF non-ACPI code will return 0 from platform_get_irq() to indicate that IRQ is not assigned.

We either need to stop doing this in platform_get_irq(), or the conditions in this patch and followups should be "irq <= 0" and we need to make sure we do not accidentally return 0 from probe ...

Quoted 6 lines

Hi,

It's then contradictory to platform_get_irq documentation which explicitly says - zero will not be returned on error. This was also clarified in commit e330b9a6bb35 ("platform: don't return 0 from platform_get_irq[_byname]() on error").

It was for OF/ACPI, but not for resources described via DEFINE_RES_IRQ or other means. However I see we added a big fat WARN_ON() in case if we end up returning 0 still, so I will be applying your patches.

Thanks.

Signature · 1 line
Dmitry