Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lee Jones" <lee@kernel.org>, linux-gpio@vger.kernel.org
Subject: Re: [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind
Date: Thu, 03 Dec 2026 21:13:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-248674@kernel.org> (raw)
In-Reply-To: <20261203205606.3905705-4-lee@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] gpio: mvebu: unsynchronized chained IRQ teardown on unbind
--

commit 654c33aa50f3c81332c15236e0d1862887658524
Author: Lee Jones <lee@kernel.org>

gpio: mvebu: Clear chained IRQ handlers on unbind

This commit registers a devm cleanup action in mvebu_gpio_probe() to clear
each bank's chained IRQ handler when the device is unbound.

> diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> index 8cb240a46a175..b9e1c4d02f579 100644
> --- a/drivers/gpio/gpio-mvebu.c
> +++ b/drivers/gpio/gpio-mvebu.c
> @@ -1182,6 +1182,17 @@ static void mvebu_gpio_remove_irq_domain(void *data)
>  	irq_domain_remove(domain);
>  }
>  
> +static void mvebu_gpio_remove_chained_handlers(void *data)
> +{
> +	struct mvebu_gpio_chip *mvchip = data;
> +
> +	for (unsigned int i = 0; i < ARRAY_SIZE(mvchip->bank_irq); i++) {
> +		if (mvchip->bank_irq[i] > 0)
> +			irq_set_chained_handler_and_data(mvchip->bank_irq[i],
> +							 NULL, NULL);
> +	}
> +}
> +
>  static int mvebu_gpio_probe(struct platform_device *pdev)
>  {
>  	struct mvebu_gpio_chip *mvchip;

[Severity: Medium]
Can unbinding the device still use-after-free mvchip, its regmaps, and
mvchip->domain if a GPIO bank interrupt is already running on another CPU?

irq_set_chained_handler_and_data() clears handler_data, masks the IRQ, and
installs handle_bad_irq under desc->lock, then returns without waiting for
an in-flight chained handler.  Chained flow handlers run in hardirq context
without holding desc->lock or setting IRQD_IRQ_INPROGRESS:

CPU0                                 CPU1
                                     mvebu_gpio_irq_handler()
                                       mvchip = irq_desc_get_handler_data()
mvebu_gpio_remove_chained_handlers()
  irq_set_chained_handler_and_data()
mvebu_gpio_remove_irq_domain()
... (devres frees regmaps, mvchip)
                                       regmap_read(mvchip->regs, ...)
                                         <-- use-after-free

This also leaves the GPIO interrupt mask registers enabled.  On parent
controllers without irq_eoi, such as Armada XP's mpic_irq_chip, an
in-flight handler's chained_irq_exit() calls chip->irq_unmask() after
teardown masked the bank IRQ, leaving it unmasked with handle_bad_irq.

Because chained handlers do not set IRQD_IRQ_INPROGRESS and mpic_irq_chip
lacks irq_get_irqchip_state, synchronize_irq() alone is not enough.  Mask
the GPIO interrupts, detach the handlers, wait for in-flight hardirqs
(e.g. synchronize_rcu()), and ensure parent IRQs stay masked before freeing.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203205606.3905705-1-lee@kernel.org?part=3

  reply	other threads:[~2026-12-03 21:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 20:54 [PATCH 00/10] gpio: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 20:54 ` [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe() Lee Jones
2026-12-03 20:55 ` [PATCH 02/10] gpiolib: acpi: Hold gpio_device reference in acpi_dev_gpio_irq_wake_get_by() Lee Jones
2026-12-03 20:55 ` [PATCH 03/10] gpio: mvebu: Clear chained IRQ handlers on unbind Lee Jones
2026-12-03 21:13   ` sashiko-bot [this message]
2026-12-03 20:55 ` [PATCH 04/10] gpio: rockchip: Unregister gpiochip on pin-range lookup errors Lee Jones
2026-12-03 20:55 ` [PATCH 05/10] gpiolib: Avoid undersized array bitmap in set fastpath Lee Jones
2026-12-03 20:55 ` [PATCH 06/10] gpio: mlxbf2: Embed context save registers to prevent suspend NULL dereference Lee Jones
2026-12-03 20:55 ` [PATCH 07/10] gpio: regmap: Use resolved chip->ngpio for default ngpio_per_reg Lee Jones
2026-12-03 20:55 ` [PATCH 08/10] gpio: mpc8xxx: Drop stale remove callback clearing chained handler Lee Jones
2026-12-03 21:17   ` sashiko-bot
2026-12-03 20:55 ` [PATCH 09/10] gpio: mpsse: Allocate DMA-safe buffer in mpsse_write() Lee Jones
2026-12-03 20:55 ` [PATCH 10/10] gpio: pcie-idio-24: Fix COS_ENABLE_RISING bit definition Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-248674@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox