Skip to contentSkip to conversation

gpio: realtek-otto: Handle errors from optional IRQ lookup

PATCH Applied [email protected] 4 participants 9 messages Aug 14 – Oct 4

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

PATCH 1/4 gpio: realtek-otto: Handle errors from optional IRQ lookup

From: bui duc phuc <[email protected]>

platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors, such as -EPROBE_DEFER and -EINVAL, should be propagated so that the caller can handle them appropriately.

Propagate negative errors other than -ENXIO.

---
 drivers/gpio/gpio-realtek-otto.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpio/gpio-realtek-otto.c +2 -0
index 4a606bad5848..5d7d28a26544 100644
@@ -423,6 +423,8 @@ static int realtek_gpio_probe(struct platform_device *pdev)
 	ctrl->chip.gc.owner = THIS_MODULE;
 
 	irq = platform_get_irq_optional(pdev, 0);
+	if (irq < 0 && irq != -ENXIO)
+		return irq;
 	if (!(dev_flags & GPIO_INTERRUPTS_DISABLED) && irq > 0) {
 		girq = &ctrl->chip.gc.irq;
 		gpio_irq_chip_set_chip(girq, &realtek_gpio_irq_chip);
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/4 gpio: mlxbf3: Handle errors from optional IRQ lookup

From: bui duc phuc <[email protected]>

platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors, such as -EPROBE_DEFER and -EINVAL, should be propagated so that the caller can handle them appropriately.

Propagate negative errors other than -ENXIO.

---
 drivers/gpio/gpio-mlxbf3.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-mlxbf3.c +3 -1
index 566326644a2c..929f64c5140a 100644
@@ -231,7 +231,9 @@ static int mlxbf3_gpio_probe(struct platform_device *pdev)
 	gc->add_pin_ranges = mlxbf3_gpio_add_pin_ranges;
 
 	irq = platform_get_irq_optional(pdev, 0);
-	if (irq >= 0) {
+	if (irq < 0 && irq != -ENXIO)
+		return irq;
+	if (irq > 0) {
 		girq = &gs->chip.gc.irq;
 		gpio_irq_chip_set_chip(girq, &gpio_mlxbf3_irqchip);
 		girq->default_type = IRQ_TYPE_NONE;
Signature · 1 line
2.43.0
#2 lore raw

PATCH 3/4 gpio: mlxbf2: Handle errors from optional IRQ lookup

In reply to [email protected]

From: bui duc phuc <[email protected]>

platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors, such as -EPROBE_DEFER and -EINVAL, should be propagated so that the caller can handle them appropriately.

Propagate negative errors other than -ENXIO.

---
 drivers/gpio/gpio-mlxbf2.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpio/gpio-mlxbf2.c +3 -1
index 4e2f3381d82b..4e5c5d196a50 100644
@@ -394,7 +394,9 @@ mlxbf2_gpio_probe(struct platform_device *pdev)
 	gc->owner = THIS_MODULE;
 
 	irq = platform_get_irq_optional(pdev, 0);
-	if (irq >= 0) {
+	if (irq < 0 && irq != -ENXIO)
+		return irq;
+	if (irq > 0) {
 		girq = &gs->chip.gc.irq;
 		gpio_irq_chip_set_chip(girq, &mlxbf2_gpio_irq_chip);
 		girq->handler = handle_simple_irq;
Signature · 1 line
2.43.0
#3 lore raw

PATCH 4/4 gpio: altera: Handle errors from optional IRQ lookup

In reply to [email protected]

From: bui duc phuc <[email protected]>

platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors, such as -EPROBE_DEFER and -EINVAL, should be propagated so that the caller can handle them appropriately.

Propagate negative errors other than -ENXIO.

---
 drivers/gpio/gpio-altera.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpio/gpio-altera.c +4 -1
index 532e3360b70e..d22f5be00745 100644
@@ -220,8 +220,11 @@ static int altera_gpio_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	mapped_irq = platform_get_irq_optional(pdev, 0);
-	if (mapped_irq < 0)
+	if (mapped_irq < 0) {
+		if (irq != -ENXIO)
+			return irq;
 		goto skip_irq;
+	}
 
 	if (device_property_read_u32(dev, "altr,interrupt-type", &reg)) {
 		dev_err(&pdev->dev,
Signature · 1 line
2.43.0
#4 lore raw
In reply to [email protected]
Quoted 9 lines · On Fri, 14 Aug 2026 11:30:25 +0700, [email protected] wrote:

platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors, such as -EPROBE_DEFER and -EINVAL, should be propagated so that the caller can handle them appropriately.

Propagate negative errors other than -ENXIO.

[...]

Applied, thanks!

[1/4] gpio: realtek-otto: Handle errors from optional IRQ lookup

      https://git.kernel.org/brgl/c/ef0d275786a3c98d1e52f1d4d89183c802af58db
[2/4] gpio: mlxbf3: Handle errors from optional IRQ lookup
      https://git.kernel.org/brgl/c/53ffd779a094d5752551dea2ba7bc787aab29229
[3/4] gpio: mlxbf2: Handle errors from optional IRQ lookup
      https://git.kernel.org/brgl/c/d8aaf6b0fdc835d10c7def7775803b28ebfd4d81
[4/4] gpio: altera: Handle errors from optional IRQ lookup
      https://git.kernel.org/brgl/c/6e6e585b603e4f679c2a33c8f0954ec88b52fd7a

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>
maintainer Reviewed-by on v1 1/4
#5 lore raw
In reply to [email protected]
Quoted 11 lines · On Fri, Aug 14, 2026 at 6:30 AM <[email protected]> wrote:

From: bui duc phuc <[email protected]>

platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors, such as -EPROBE_DEFER and -EINVAL, should be propagated so that the caller can handle them appropriately.

Propagate negative errors other than -ENXIO.

Looks good to me.

Yours,
Linus Walleij

#6 lore raw
In reply to [email protected]
Quoted 7 lines · On Fri, Aug 14, 2026 at 11:30:25AM +0700, [email protected] wrote:

platform_get_irq_optional() returns a positive IRQ number on success or a negative error code on failure. For an optional IRQ, -ENXIO indicates that no optional IRQ is available. Other errors, such as -EPROBE_DEFER and -EINVAL, should be propagated so that the caller can handle them appropriately.

Propagate negative errors other than -ENXIO.

Have you read the discussion [1]?
It would be better to make platform_get_irq_optional() to be actually optional.

[1]: https://lore.kernel.org/lkml/[email protected]/

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

Hi Andy,

Thank you for pointing me to the discussion.

Quoted 6 lines

Have you read the discussion [1]?
It would be better to make platform_get_irq_optional() to be actually optional.

[1]: https://lore.kernel.org/lkml/[email protected]/

However, Regardless of how the API might be redesigned in the future to return 0
or negative error codes, the fundamental requirement at the driver level remains
the same: real errors must be propagated properly.

This patch isn't concerned with the API style discussion, but rather with ensuring
that driver probe doesn't silently swallow genuine errors like ⁠-EPROBE_DEFER⁠. Proper error reporting is necessary under any reasonable API design.

Best regards
Phuc

#8 lore raw

On Sun, Oct 04, 2026 at 08:08:18AM +0700, Bui Duc Phuc wrote:

...

Quoted 13 lines

Thank you for pointing me to the discussion.

Quoted 4 lines

Have you read the discussion [1]?
It would be better to make platform_get_irq_optional() to be actually optional.

[1]: https://lore.kernel.org/lkml/[email protected]/

However, Regardless of how the API might be redesigned in the future to return 0
or negative error codes, the fundamental requirement at the driver level remains
the same: real errors must be propagated properly.

Quoted 4 lines

This patch isn't concerned with the API style discussion, but rather with ensuring
that driver probe doesn't silently swallow genuine errors like ⁠-EPROBE_DEFER⁠. Proper error reporting is necessary under any reasonable API design.

Yes, but doing specific error handling is usually not a good idea as it adds ambiguity. Like -EINVAL was used to check if the device property is present or not at the time of trying to parse it. This was specifically clarified in the documentation [2]. This is just an example of why the checking over a certain error code is not good.

[2]: 70fa0c308aa2 ("device property: Document how to check for the property presence")

Signature · 2 lines
With Best Regards,
Andy Shevchenko