All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Adrian Ambrozewicz" <aambrozewicz@nvidia.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH v3 6/6] gpiolib: let the character device free its IRQs first on chip removal
Date: Tue, 20 Oct 2026 13:23:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-179021@kernel.org> (raw)
In-Reply-To: <20261020-gpiolib-chip-removal-v3-6-aambrozewicz@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] gpiolib: cdev: negative gpiod_get_value_cansleep() treated as rising edge
--

commit 526f1d7ea8a308d5657aec9728c6582d403f73c5
Author: Adrian Ambrozewicz <aambrozewicz@nvidia.com>

gpiolib: let the character device free its IRQs first on chip removal

This commit reorders GPIO chip removal so that the device notifier runs
after gdev->chip is cleared and before remaining IRQs and the irqchip are
freed, while synchronizing character device release paths with the
notifier.

Link: https://lore.kernel.org/all/20240227113426.253232-1-herve.codina@bootlin.com/

> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index e923512febf15..5eb53f8c5d34c 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c

[ ... ]

> @@ -1422,7 +1433,6 @@ void gpiochip_remove(struct gpio_chip *gc)
>  	/* FIXME: should the legacy sysfs handling be moved to gpio_device? */
>  	gpiochip_sysfs_unregister(gc);
>  	gpiochip_free_hogs(gc);
> -	gpiochip_free_remaining_irqs(gc);
>  
>  	scoped_guard(mutex, &gpio_devices_lock)
>  		list_del_rcu(&gdev->list);
> @@ -1431,6 +1441,14 @@ void gpiochip_remove(struct gpio_chip *gc)
>  	/* Numb the device, cancelling all outstanding operations */
>  	rcu_assign_pointer(gdev->chip, NULL);
>  	synchronize_srcu(&gdev->srcu);
> +
> +	/*
> +	 * No new interrupts can be requested through the character device now.
> +	 * Have it free the ones it holds before forcibly freeing the rest, and
> +	 * both before the irqchip and its mappings go away.
> +	 */
> +	blocking_notifier_call_chain(&gdev->device_notifier, 0, NULL);
> +	gpiochip_free_remaining_irqs(gc);
>  	gpio_device_teardown_shared(gdev);
>  	gpiochip_irqchip_remove(gc);
>  	acpi_gpiochip_remove(gc);

[Severity: Medium]
With character device IRQs now freed in the notifier callback after
rcu_assign_pointer(gdev->chip, NULL), can an in-flight dual-edge interrupt
handler queue a spurious rising-edge event to userspace?

Previously, gpiochip_free_remaining_irqs() stopped and synchronized all
GPIOD_FLAG_USED_AS_IRQ handlers before gdev->chip was cleared. With this
change, if edge_irq_thread() or lineevent_irq_thread() runs between
rcu_assign_pointer(gdev->chip, NULL) and free_irq() in the notifier,
gpiod_get_value_cansleep() returns -ENODEV.

In drivers/gpio/gpiolib-cdev.c, edge_irq_thread() passes the return value
directly to line_event_id():

	switch (READ_ONCE(line->edflags) & GPIO_V2_LINE_EDGE_FLAGS) {
	case GPIO_V2_LINE_FLAG_EDGE_BOTH:
		le.id = line_event_id(gpiod_get_value_cansleep(line->desc));
		break;

where line_event_id() treats any non-zero value as
GPIO_V2_LINE_EVENT_RISING_EDGE. Similarly, lineevent_irq_thread() checks:

	if (le->eflags & GPIOEVENT_REQUEST_RISING_EDGE
	    && le->eflags & GPIOEVENT_REQUEST_FALLING_EDGE) {
		int level = gpiod_get_value_cansleep(le->desc);

		if (level)
			/* Emit low-to-high event */
			ge.id = GPIOEVENT_EVENT_RISING_EDGE;

Unlike debounce_work_func(), which drops the event when level < 0, both
threaded IRQ handlers treat -ENODEV as a logical high level and push a
rising-edge event into the kfifo.

Should edge_irq_thread() and lineevent_irq_thread() also check for a
negative return from gpiod_get_value_cansleep() and drop the event?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261020-gpiolib-chip-removal-v3-0-aambrozewicz@nvidia.com?part=6

  reply	other threads:[~2026-10-20 13:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 13:00 [PATCH v3 0/6] gpiolib: fix chip removal with lines still requested from user space Adrian Ambrozewicz
2026-10-20 13:00 ` [PATCH v3 1/6] gpiolib: wait for pending label frees before cleaning up desc_srcu Adrian Ambrozewicz
2026-10-20 13:00 ` [PATCH v3 2/6] gpiolib: free the label of lines released after their chip was removed Adrian Ambrozewicz
2026-10-20 13:19   ` sashiko-bot
2026-10-21  9:55     ` Adrian Ambrozewicz
2026-10-21 10:03       ` Bartosz Golaszewski
2026-10-20 13:00 ` [PATCH v3 3/6] gpiolib: cdev: do not free line IRQs again after the chip is removed Adrian Ambrozewicz
2026-10-20 13:00 ` [PATCH v3 4/6] gpiolib: cdev: don't sleep in the SRCU read section in read() Adrian Ambrozewicz
2026-10-20 13:00 ` [PATCH v3 5/6] gpiolib: cdev: don't leak the IRQ name when the chip is removed Adrian Ambrozewicz
2026-10-20 13:00 ` [PATCH v3 6/6] gpiolib: let the character device free its IRQs first on chip removal Adrian Ambrozewicz
2026-10-20 13:23   ` sashiko-bot [this message]
2026-10-21  9:55     ` Adrian Ambrozewicz
2026-10-21 10:05       ` Bartosz Golaszewski

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-179021@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aambrozewicz@nvidia.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.