[PATCH 2/2] pinctrl: ocelot: do not use the chained irqchip behind a sleeping bus
From: Jens Emil Schulz Østergaard
Date: Mon Nov 09 2026 - 09:04:50 EST
Since the driver can use a regmap on a bus that can sleep, as for
VSC7512 attached over SPI, it still registers the gpiochip as not
sleeping and adds the chained irqchip when the node has an interrupt.
The chained handler and the irq_chip callbacks run in atomic context and
access the registers through that regmap, and consumers may use the
lines of a gpiochip that is not marked as sleeping from atomic context.
Mark the gpiochip as sleeping when the regmap can sleep, and do not
register the chained irqchip in that case.
The issue was found by code inspection and reproduced on a lan9668
board (pcb8385) with a lan9645x attached over SPI, whose pinctrl node
has an interrupt, by requesting an edge interrupt on one of its GPIOs
through the GPIO character device:
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:623
in_atomic(): 1, irqs_disabled(): 128, non_block: 0, pid: 420, name: gpiomon
preempt_count: 1, expected: 0
locks held by gpiomon/420: 3, last CPU#0:
#0: 84463cd0 (&gdev->srcu){.+.+}-{0:0}, at: lineinfo_get+0x13f/0x140
#1: 838bbd30 (request_class){+.+.}-{4:4}, at: __setup_irq+0xe8/0x5c0
#2: 838bbc70 (lock_class){-...}-{2:2}, at: __setup_irq+0x104/0x5c0
...
Call trace:
...
mutex_lock_nested from regmap_update_bits_base+0x1c/0x80
regmap_update_bits_base from ocelot_irq_unmask+0x42/0x80
ocelot_irq_unmask from irq_enable+0x1e/0x80
irq_enable from irq_startup+0x64/0xc0
irq_startup from __setup_irq+0x38c/0x5c0
__setup_irq from request_threaded_irq+0x86/0x140
request_threaded_irq from edge_detector_setup+0x1d8/0x240
edge_detector_setup from linereq_create+0x3e2/0x540
linereq_create from gpio_ioctl+0xa4/0x240
With the fix the lan9645x gpiochip is registered as sleeping and
without the chained irqchip, the request fails with -ENXIO instead and
without lockdep reports.
Fixes: 181f604b33cd ("pinctrl: ocelot: add ability to be used in a non-mmio configuration")
Signed-off-by: Jens Emil Schulz Østergaard <jensemil.schulzostergaard@xxxxxxxxxxxxx>
---
drivers/pinctrl/pinctrl-ocelot.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/pinctrl-ocelot.c b/drivers/pinctrl/pinctrl-ocelot.c
index 06dd49782d74..90a1f859db67 100644
--- a/drivers/pinctrl/pinctrl-ocelot.c
+++ b/drivers/pinctrl/pinctrl-ocelot.c
@@ -2367,8 +2367,9 @@ static int ocelot_gpiochip_register(struct platform_device *pdev,
gc->parent = &pdev->dev;
gc->base = -1;
gc->label = "ocelot-gpio";
+ gc->can_sleep = regmap_might_sleep(info->map);
- irq = platform_get_irq_optional(pdev, 0);
+ irq = gc->can_sleep ? 0 : platform_get_irq_optional(pdev, 0);
if (irq > 0) {
girq = &gc->irq;
gpio_irq_chip_set_chip(girq, &ocelot_irqchip);
--
2.52.0