[PATCH] gpio: cadence: Restore irqsave locking for the generic chip lock

From: Hiroki Nakajima

Date: Sat Dec 05 2026 - 22:27:11 EST


Commit 76045e90400b ("gpio: cadence: use lock guards") replaced
raw_spin_lock_irqsave() with guard(raw_spinlock), and commit
47ecff3839ca ("gpio: cadence: use new generic GPIO chip API") carried
this over as guard(gpio_generic_lock). The plain guard leaves local
interrupts unchanged while cdns_gpio_request() and cdns_gpio_free()
hold the generic GPIO chip lock.

cdns_gpio_irq_set_type() takes the same lock, and the IRQ core calls it
with the interrupt descriptor lock held. The GPIO interrupt flow handler
(handle_level_irq()) takes the descriptor lock in hard interrupt
context. If a GPIO interrupt arrives on a CPU that holds the chip lock
in cdns_gpio_request() or cdns_gpio_free(), while another CPU holds the
descriptor lock of that interrupt in irq_set_irq_type() and waits for
the chip lock, the two CPUs deadlock:

CPU0 CPU1
---- ----
lock(&chip->lock) lock(&desc->lock)
<GPIO interrupt> lock(&chip->lock)
lock(&desc->lock)

Use guard(gpio_generic_lock_irqsave) to restore the original locking.
cdns_gpio_irq_set_type() already runs with interrupts disabled, but it
is converted as well for consistency.

Found by static analysis; compile-tested only (not tested on hardware).

Fixes: 76045e90400b ("gpio: cadence: use lock guards")
Cc: stable@xxxxxxxxxxxxxxx
Assisted-by: Gemini, Claude and OpenAI Codex
Signed-off-by: Hiroki Nakajima <3na7nanana@xxxxxxxxx>
---
drivers/gpio/gpio-cadence.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpio-cadence.c b/drivers/gpio/gpio-cadence.c
index 6baa5d6cd167..e8b5ebd8d294 100644
--- a/drivers/gpio/gpio-cadence.c
+++ b/drivers/gpio/gpio-cadence.c
@@ -55,7 +55,7 @@ static int cdns_gpio_request(struct gpio_chip *chip, unsigned int offset)
{
struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip);

- guard(gpio_generic_lock)(&cgpio->gen_gc);
+ guard(gpio_generic_lock_irqsave)(&cgpio->gen_gc);

iowrite32(ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE) & ~BIT(offset),
cgpio->regs + CDNS_GPIO_BYPASS_MODE);
@@ -67,7 +67,7 @@ static void cdns_gpio_free(struct gpio_chip *chip, unsigned int offset)
{
struct cdns_gpio_chip *cgpio = gpiochip_get_data(chip);

- guard(gpio_generic_lock)(&cgpio->gen_gc);
+ guard(gpio_generic_lock_irqsave)(&cgpio->gen_gc);

iowrite32(ioread32(cgpio->regs + CDNS_GPIO_BYPASS_MODE) |
(BIT(offset) & cgpio->bypass_orig),
@@ -102,7 +102,7 @@ static int cdns_gpio_irq_set_type(struct irq_data *d, unsigned int type)
u32 mask = BIT(d->hwirq);
int ret = 0;

- guard(gpio_generic_lock)(&cgpio->gen_gc);
+ guard(gpio_generic_lock_irqsave)(&cgpio->gen_gc);

int_value = ioread32(cgpio->regs + CDNS_GPIO_IRQ_VALUE) & ~mask;
int_type = ioread32(cgpio->regs + CDNS_GPIO_IRQ_TYPE) & ~mask;

base-commit: 19cc08c1a6a650f8e54c0461ff198be6448f425d
--
2.43.0