Skip to contentSkip to conversation

gpio-mlxbf2: only get IRQ for device instances 0 and 3

PATCH In review David Thompson 3 participants 4 messages Jul 21, 2025 – Jul 28, 2025

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

PATCH v3 1/1 gpio-mlxbf2: only get IRQ for device instances 0 and 3

The gpio-mlxbf2 driver interfaces with four GPIO controllers, device instances 0-3. There are two IRQ resources shared between the four controllers, and they are found in the ACPI table for device instances 0 and 3. The driver should not attempt to get an IRQ resource when probing device instance 1 or 2, otherwise the following error is logged:
mlxbf2_gpio MLNXBF22:01: error -ENXIO: IRQ index 0 not found

Fixes 2b725265cb08 ("gpio: mlxbf2: Introduce IRQ support")

---
v3: added version history
v2: added tag "Cc: [email protected]"

 drivers/gpio/gpio-mlxbf2.c | 56 ++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 20 deletions(-)
drivers/gpio/gpio-mlxbf2.c +36 -20
index 6f3dda6b635f..fc56ac81e344 100644
@@ -353,7 +353,9 @@ mlxbf2_gpio_probe(struct platform_device *pdev)
 	struct gpio_chip *gc;
 	unsigned int npins;
 	const char *name;
+	char *colon_ptr;
 	int ret, irq;
+	long num;
 
 	name = dev_name(dev);
 
@@ -397,26 +399,40 @@ mlxbf2_gpio_probe(struct platform_device *pdev)
 	gc->ngpio = npins;
 	gc->owner = THIS_MODULE;
 
-	irq = platform_get_irq(pdev, 0);
-	if (irq >= 0) {
-		girq = &gs->gc.irq;
-		gpio_irq_chip_set_chip(girq, &mlxbf2_gpio_irq_chip);
-		girq->handler = handle_simple_irq;
-		girq->default_type = IRQ_TYPE_NONE;
-		/* This will let us handle the parent IRQ in the driver */
-		girq->num_parents = 0;
-		girq->parents = NULL;
-		girq->parent_handler = NULL;
-
-		/*
-		 * Directly request the irq here instead of passing
-		 * a flow-handler because the irq is shared.
-		 */
-		ret = devm_request_irq(dev, irq, mlxbf2_gpio_irq_handler,
-				       IRQF_SHARED, name, gs);
-		if (ret) {
-			dev_err(dev, "failed to request IRQ");
-			return ret;
+	colon_ptr = strchr(dev_name(dev), ':');
+	if (!colon_ptr) {
+		dev_err(dev, "invalid device name format\n");
+		return -EINVAL;
+	}
+
+	ret = kstrtol(++colon_ptr, 16, &num);
+	if (ret) {
+		dev_err(dev, "invalid device instance\n");
+		return ret;
+	}
+
+	if (!num || num == 3) {
+		irq = platform_get_irq(pdev, 0);
+		if (irq >= 0) {
+			girq = &gs->gc.irq;
+			gpio_irq_chip_set_chip(girq, &mlxbf2_gpio_irq_chip);
+			girq->handler = handle_simple_irq;
+			girq->default_type = IRQ_TYPE_NONE;
+			/* This will let us handle the parent IRQ in the driver */
+			girq->num_parents = 0;
+			girq->parents = NULL;
+			girq->parent_handler = NULL;
+
+			/*
+			 * Directly request the irq here instead of passing
+			 * a flow-handler because the irq is shared.
+			 */
+			ret = devm_request_irq(dev, irq, mlxbf2_gpio_irq_handler,
+					       IRQF_SHARED, name, gs);
+			if (ret) {
+				dev_err(dev, "failed to request IRQ");
+				return ret;
+			}
 		}
 	}
 
Signature · 1 line
2.30.1
#1 lore raw
Quoted 60 lines · David Thompson

The gpio-mlxbf2 driver interfaces with four GPIO controllers, device instances 0-3. There are two IRQ resources shared between the four controllers, and they are found in the ACPI table for device instances 0 and 3. The driver should not attempt to get an IRQ resource when probing device instance 1 or 2, otherwise the following error is logged:
mlxbf2_gpio MLNXBF22:01: error -ENXIO: IRQ index 0 not found

Fixes 2b725265cb08 ("gpio: mlxbf2: Introduce IRQ support")

---
v3: added version history
v2: added tag "Cc: [email protected]"

 drivers/gpio/gpio-mlxbf2.c | 56 ++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 20 deletions(-)
drivers/gpio/gpio-mlxbf2.c +4 -20
index 6f3dda6b635f..fc56ac81e344 100644
@@ -353,7 +353,9 @@ mlxbf2_gpio_probe(struct platform_device *pdev)
        struct gpio_chip *gc;
        unsigned int npins;
        const char *name;
+       char *colon_ptr;
        int ret, irq;
+       long num;
 
        name = dev_name(dev);
 
@@ -397,26 +399,40 @@ mlxbf2_gpio_probe(struct platform_device *pdev)
        gc->ngpio = npins;
        gc->owner = THIS_MODULE;
 
-       irq = platform_get_irq(pdev, 0);
-       if (irq >= 0) {
-               girq = &gs->gc.irq;
-               gpio_irq_chip_set_chip(girq, &mlxbf2_gpio_irq_chip);
-               girq->handler = handle_simple_irq;
-               girq->default_type = IRQ_TYPE_NONE;
-               /* This will let us handle the parent IRQ in the driver */
-               girq->num_parents = 0;
-               girq->parents = NULL;
-               girq->parent_handler = NULL;
-
-               /*
-                * Directly request the irq here instead of passing
-                * a flow-handler because the irq is shared.
-                */
-               ret = devm_request_irq(dev, irq, mlxbf2_gpio_irq_handler,
-                                      IRQF_SHARED, name, gs);
-               if (ret) {
-                       dev_err(dev, "failed to request IRQ");
-                       return ret;
+       colon_ptr = strchr(dev_name(dev), ':');
+       if (!colon_ptr) {

drivers/gpio/gpio-mlxbf2.c mlxbf2_gpio_probe(struct platform_device *pdev) · line 413

Quoted 10 lines
drivers/gpio/gpio-mlxbf2.c +10 -0
+               dev_err(dev, "invalid device name format\n");
+               return -EINVAL;
+       }
+
+       ret = kstrtol(++colon_ptr, 16, &num);
+       if (ret) {
+               dev_err(dev, "invalid device instance\n");
+               return ret;
+       }
+

That is *really* fragile. Andy, Mika: does this look remotely correct to you? I don't know much about ACPI systems.

Bart

Quoted 28 lines
drivers/gpio/gpio-mlxbf2.c +22 -1
+       if (!num || num == 3) {
+               irq = platform_get_irq(pdev, 0);
+               if (irq >= 0) {
+                       girq = &gs->gc.irq;
+                       gpio_irq_chip_set_chip(girq, &mlxbf2_gpio_irq_chip);
+                       girq->handler = handle_simple_irq;
+                       girq->default_type = IRQ_TYPE_NONE;
+                       /* This will let us handle the parent IRQ in the driver */
+                       girq->num_parents = 0;
+                       girq->parents = NULL;
+                       girq->parent_handler = NULL;
+
+                       /*
+                        * Directly request the irq here instead of passing
+                        * a flow-handler because the irq is shared.
+                        */
+                       ret = devm_request_irq(dev, irq, mlxbf2_gpio_irq_handler,
+                                              IRQF_SHARED, name, gs);
+                       if (ret) {
+                               dev_err(dev, "failed to request IRQ");
+                               return ret;
+                       }
                }
        }
 
--

2.30.1

#2 lore raw
Quoted 9 lines · Bartosz Golaszewski
Quoted 8 lines · David Thompson

The gpio-mlxbf2 driver interfaces with four GPIO controllers, device instances 0-3. There are two IRQ resources shared between the four controllers, and they are found in the ACPI table for device instances 0 and 3. The driver should not attempt to get an IRQ resource when probing device instance 1 or 2, otherwise the following error is logged:
mlxbf2_gpio MLNXBF22:01: error -ENXIO: IRQ index 0 not found

...

Quoted 1 line
Quoted 1 line

- irq = platform_get_irq(pdev, 0);

So, why not simply change this to the _optional() call?

Quoted 26 lines
Quoted 26 lines
drivers/gpio/gpio-mlxbf2.c +7 -19
-       if (irq >= 0) {
-               girq = &gs->gc.irq;
-               gpio_irq_chip_set_chip(girq, &mlxbf2_gpio_irq_chip);
-               girq->handler = handle_simple_irq;
-               girq->default_type = IRQ_TYPE_NONE;
-               /* This will let us handle the parent IRQ in the driver */
-               girq->num_parents = 0;
-               girq->parents = NULL;
-               girq->parent_handler = NULL;
-
-               /*
-                * Directly request the irq here instead of passing
-                * a flow-handler because the irq is shared.
-                */
-               ret = devm_request_irq(dev, irq, mlxbf2_gpio_irq_handler,
-                                      IRQF_SHARED, name, gs);
-               if (ret) {
-                       dev_err(dev, "failed to request IRQ");
-                       return ret;
+       colon_ptr = strchr(dev_name(dev), ':');
+       if (!colon_ptr) {
+               dev_err(dev, "invalid device name format\n");
+               return -EINVAL;
+       }
+
+       ret = kstrtol(++colon_ptr, 16, &num);
Quoted 8 lines

drivers/gpio/gpio-mlxbf2.c mlxbf2_gpio_probe(struct platform_device *pdev) · line 413

Quoted 5 lines
drivers/gpio/gpio-mlxbf2.c +5 -0
+       if (ret) {
+               dev_err(dev, "invalid device instance\n");
+               return ret;
+       }
+

That is *really* fragile. Andy, Mika: does this look remotely correct to you? I don't know much about ACPI systems.

I totally agree with you. This is an ugly hack and here is formal NAK from me. The ACPI tables that doesn't provide an IRQ resources (in any of its possible type) can be simply ignored by not requesting that IRQ. The message above AFAICT is harmless. Above I proposed the better fix.

Quoted 24 lines
Quoted 24 lines
drivers/gpio/gpio-mlxbf2.c +22 -0
+       if (!num || num == 3) {
+               irq = platform_get_irq(pdev, 0);
+               if (irq >= 0) {
+                       girq = &gs->gc.irq;
+                       gpio_irq_chip_set_chip(girq, &mlxbf2_gpio_irq_chip);
+                       girq->handler = handle_simple_irq;
+                       girq->default_type = IRQ_TYPE_NONE;
+                       /* This will let us handle the parent IRQ in the driver */
+                       girq->num_parents = 0;
+                       girq->parents = NULL;
+                       girq->parent_handler = NULL;
+
+                       /*
+                        * Directly request the irq here instead of passing
+                        * a flow-handler because the irq is shared.
+                        */
+                       ret = devm_request_irq(dev, irq, mlxbf2_gpio_irq_handler,
+                                              IRQF_SHARED, name, gs);
+                       if (ret) {
+                               dev_err(dev, "failed to request IRQ");
+                               return ret;
+                       }
                }
        }
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 23 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Wednesday, July 23, 2025 9:58 AM
To: Bartosz Golaszewski <[email protected]>
Cc: David Thompson <[email protected]>; Mika Westerberg <[email protected]>; [email protected]; [email protected]; Asmaa Mnebhi <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Shravan Ramani <[email protected]>
Subject: Re: [PATCH v3] gpio-mlxbf2: only get IRQ for device instances 0 and 3

Quoted 1 line · Bartosz Golaszewski

On Mon, Jul 21, 2025 at 6:22 PM David Thompson <[email protected]>

Quoted 8 lines · wrote:
Quoted 8 lines

The gpio-mlxbf2 driver interfaces with four GPIO controllers, device instances 0-3. There are two IRQ resources shared between the four controllers, and they are found in the ACPI table for device instances 0 and 3. The driver should not attempt to get an IRQ resource when probing device instance 1 or 2, otherwise the following error is logged:
mlxbf2_gpio MLNXBF22:01: error -ENXIO: IRQ index 0 not found

Quoted 6 lines

...

Quoted 1 line
Quoted 1 line

- irq = platform_get_irq(pdev, 0);

So, why not simply change this to the _optional() call?

Thanks for the tip, Andy.

I've sent a v4 patch that uses this approach.

Thanks,
- Dave