Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Long Zhao" <longzhao@ambarella.com>, linux-gpio@vger.kernel.org
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v14 10/14] gpio: pl061: switch data path to gpio-regmap
Date: Tue, 10 Nov 2026 05:51:48 +0000	[thread overview]
Message-ID: <sashiko-outbox-206348@kernel.org> (raw)
In-Reply-To: <20261110-cv75-gpio-v14-10-e586aad0467a@ambarella.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] gpio: pl061: dropping IRQ resource helpers breaks IRQ locking
  and unbind
--

commit d4312a121fe3ffeafa0c808d47b54f2cad54a4cd
Author: Long Zhao <longzhao@ambarella.com>

gpio: pl061: switch data path to gpio-regmap

This commit converts the PL061 GPIO data path to gpio-regmap while keeping
a custom irq_chip and instantiating an external irq_domain.

> diff --git a/drivers/gpio/gpio-pl061.c b/drivers/gpio/gpio-pl061.c
> index 27ed759486caf..cb1ef0f3774c1 100644
> --- a/drivers/gpio/gpio-pl061.c
> +++ b/drivers/gpio/gpio-pl061.c

[ ... ]

> @@ -229,54 +198,47 @@ static int pl061_irq_type(struct irq_data *d, unsigned trigger)

[ ... ]

>  static void pl061_irq_mask(struct irq_data *d)
>  {
> -	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> -	struct pl061 *pl061 = gpiochip_get_data(gc);
> -	u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
> +	struct pl061 *pl061 = irq_data_get_irq_chip_data(d);
> +	unsigned int mask = pl061_line_mask(pl061, irqd_to_hwirq(d));
>  
> -	scoped_guard(raw_spinlock, &pl061->lock)
> -		regmap_clear_bits(pl061->regmap, GPIOIE, mask);
> -
> -	gpiochip_disable_irq(gc, d->hwirq);
> +	regmap_clear_bits(pl061->regmap, pl061->data->regs->ie, mask);
>  }
>  
>  static void pl061_irq_unmask(struct irq_data *d)
>  {
> -	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
> -	struct pl061 *pl061 = gpiochip_get_data(gc);
> -	u8 mask = BIT(irqd_to_hwirq(d) % PL061_GPIO_NR);
> -
> -	gpiochip_enable_irq(gc, d->hwirq);
> +	struct pl061 *pl061 = irq_data_get_irq_chip_data(d);
> +	unsigned int mask = pl061_line_mask(pl061, irqd_to_hwirq(d));
>  
> -	scoped_guard(raw_spinlock, &pl061->lock)
> -		regmap_set_bits(pl061->regmap, GPIOIE, mask);
> +	regmap_set_bits(pl061->regmap, pl061->data->regs->ie, mask);
>  }

[ ... ]

> @@ -320,67 +280,169 @@ static const struct irq_chip pl061_irq_chip = {
>  	.irq_set_wake		= pl061_irq_set_wake,
>  	.irq_print_chip		= pl061_irq_print_chip,
>  	.flags			= IRQCHIP_IMMUTABLE,
> -	GPIOCHIP_IRQ_RESOURCE_HELPERS,
> +};

[ ... ]

> +	if (irq) {
> +		const struct irq_domain_info info = {
> +			.fwnode		= dev_fwnode(dev),
> +			.size		= data->ngpio,
> +			.hwirq_max	= data->ngpio,
> +			.ops		= &pl061_irq_domain_ops,
> +			.host_data	= pl061,
> +		};
> +
> +		pl061->irq_domain = devm_irq_domain_instantiate(dev, &info);
> +		if (IS_ERR(pl061->irq_domain))
> +			return PTR_ERR(pl061->irq_domain);
> +
> +		/*
> +		 * Registered before the gpiochip so unbind runs it after
> +		 * gpiochip_free_remaining_irqs(), while the domain is still
> +		 * alive. devm removes the domain after this action.
> +		 */
> +		ret = devm_add_action_or_reset(dev, pl061_dispose_irq_mappings, pl061);
> +		if (ret)
> +			return ret;
> +	}

[Severity: High]
Does dropping GPIOCHIP_IRQ_RESOURCE_HELPERS and
gpiochip_enable_irq()/gpiochip_disable_irq() break IRQ teardown on unbind
and gpiolib's direction vs. IRQ protections?

Without those helpers, GPIOD_FLAG_USED_AS_IRQ and GPIOD_FLAG_IRQ_IS_ENABLED
are never set on the GPIO descriptors.  Although the comment above
pl061_dispose_irq_mappings() relies on gpiochip_free_remaining_irqs()
cleaning up active interrupts first during unbind,
gpiochip_free_remaining_irqs() only iterates over descriptors with
GPIOD_FLAG_USED_AS_IRQ set and becomes a no-op.

If a line has an active interrupt when the device is unbound (for example,
via GPIO_V2_GET_LINE_IOCTL edge detection), pl061_dispose_irq_mappings()
calls irq_dispose_mapping() -> free_desc() while desc->action and the
threaded IRQ handler are still installed, warning in remove_proc_entry()
and freeing the irq_desc; a later free_irq() then sees irq_to_desc(virq) ==
NULL and leaks the irqaction while leaving edge_irq_thread running with a
dangling dev_id pointer.

Leaving those flags unset also regressions direction and module lifetime
enforcement: requesting an IRQ on a line configured as an output is no
longer rejected by gpiochip_lock_as_irq(), switching a line with an active
enabled IRQ to output mode is no longer blocked by
gpiod_direction_output_nonotify(), and module refcounting in
gpiochip_reqres_irq()/gpiochip_relres_irq() is bypassed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110-cv75-gpio-v14-0-e586aad0467a@ambarella.com?part=10

  reply	other threads:[~2026-11-10  5:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10  4:32 [PATCH v14 00/14] gpio: add Ambarella CV75 PL061 support Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 01/14] dt-bindings: gpio: pl061: add Ambarella CV75 variant Long Zhao via B4 Relay
2026-11-10  4:48   ` sashiko-bot
2026-11-10  4:32 ` [PATCH v14 02/14] gpio: regmap: add GPIO_REGMAP_QUIRK_SET_AFTER_DIR Long Zhao via B4 Relay
2026-11-10  5:00   ` sashiko-bot
2026-11-10  4:32 ` [PATCH v14 03/14] gpio: regmap: remove gpiochip before tearing down irqchip Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 04/14] gpio: pl061: drop redundant pending check in the IRQ handler Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 05/14] gpio: pl061: convert register access to regmap Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 06/14] gpio: pl061: use IRQ_TYPE_LEVEL_MASK and IRQ_TYPE_EDGE_BOTH Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 07/14] gpio: pl061: use cleanup helpers for locks Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 08/14] gpio: pl061: keep the parent device in a local Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 09/14] gpiolib: request ACPI GPIO events for external IRQ domains Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 10/14] gpio: pl061: switch data path to gpio-regmap Long Zhao via B4 Relay
2026-11-10  5:51   ` sashiko-bot [this message]
2026-11-10  4:32 ` [PATCH v14 11/14] gpio: pl061: add Ambarella register-layout variant Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 12/14] gpio: pl061: tidy up IRQ trigger logging Long Zhao via B4 Relay
2026-11-10  4:32 ` [PATCH v14 13/14] lib/string_choices: add str_rising_falling() Long Zhao via B4 Relay
2026-11-10 10:01   ` Andy Shevchenko
2026-11-10  4:32 ` [PATCH v14 14/14] gpio: pl061: use string_choices helpers for IRQ trigger logging Long Zhao via B4 Relay
2026-11-10 13:55   ` Andy Shevchenko

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-206348@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=longzhao@ambarella.com \
    --cc=robh@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