All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Joseph Telaak" <joseph@telaak.dev>
Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 2/2] gpio: Add Siflower GPIO controller driver
Date: Mon, 23 Nov 2026 01:49:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-228534@kernel.org> (raw)
In-Reply-To: <20261122-sf19a2890-gpio-v3-2-3a4857ebc84a@telaak.dev>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] gpio: siflower: non-raw regmap spinlock acquired in raw IRQ and
  hardirq contexts
- [High] gpio: siflower: IRQ domain and chained handlers registered
  before priv->gpio
- [Medium] gpio: siflower: undisposed virtual IRQ mappings in
  priv->domain on teardown
- [Medium] gpio: siflower: Kconfig dependency on undefined symbol
  MACH_SIFLOWER_MIPS
--

commit 86affe3feaf16149d7ee585860ef5d5bfff26ad5
Author: Qingfang Deng <qingfang.deng@siflower.com.cn>

gpio: Add Siflower GPIO controller driver

This commit adds a GPIO and interrupt controller driver for Siflower MIPS
and RISC-V SoCs using gpio-regmap and regmap-mmio.

> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 55e4280029d86..0b52fc2a5335e 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -721,6 +721,20 @@ config GPIO_SIFIVE
>  	help
>  	  Say yes here to support the GPIO device on SiFive SoCs.
>  
> +config GPIO_SIFLOWER
> +	tristate "Siflower GPIO support"
> +	depends on MACH_SIFLOWER_MIPS || COMPILE_TEST

[Severity: Medium]
Is MACH_SIFLOWER_MIPS defined anywhere in the tree?  Because that Kconfig
symbol does not exist (and there is no RISC-V dependency for the RISC-V
SoCs mentioned in the changelog), GPIO_SIFLOWER can only be enabled when
COMPILE_TEST is set.

> diff --git a/drivers/gpio/gpio-siflower.c b/drivers/gpio/gpio-siflower.c
> new file mode 100644
> index 0000000000000..4bf7e36960e4c
> --- /dev/null
> +++ b/drivers/gpio/gpio-siflower.c
[ ... ]
> +static const struct regmap_config sf_gpio_regmap_config = {
> +	.reg_bits	= 32,
> +	.reg_stride	= 4,
> +	.val_bits	= 32,
> +};

[Severity: High]
Should sf_gpio_regmap_config set .use_raw_spinlock = true?

Without it, devm_regmap_init_mmio() protects priv->regmap with a non-raw
spinlock_t.  sf_gpio_irq_ack(), sf_gpio_irq_mask(), sf_gpio_irq_unmask()
and sf_gpio_irq_set_type() access priv->regmap while holding the irq_desc
raw_spinlock_t, and sf_gpio_irq_handler() reads priv->regmap in hardirq
context, triggering a lockdep invalid wait context splat or sleeping in
atomic context on PREEMPT_RT.

> +static int sf_gpio_probe(struct platform_device *pdev)
> +{
[ ... ]
> +	d_info.fwnode = dev_fwnode(dev);
> +	d_info.size = soc->ngpios;
> +	d_info.hwirq_max = soc->ngpios;
> +	d_info.ops = &sf_gpio_irq_domain_ops;
> +	d_info.host_data = priv;
> +
> +	priv->domain = devm_irq_domain_instantiate(dev, &d_info);
> +	if (IS_ERR(priv->domain))
> +		return PTR_ERR(priv->domain);

[Severity: Medium]
Does teardown dispose of virtual IRQ mappings in priv->domain before the
domain is removed?

Because priv->domain is allocated externally and passed via
config.irq_domain, gpiochip_irqchip_remove() skips irq_dispose_mapping().
When devm_irq_domain_remove() then calls irq_domain_remove(), any mapped
irq_desc entries are leaked with dangling pointers to the freed domain and
priv.

> +	for (i = 0; i < ngroups; i++) {
> +		ret = platform_get_irq(pdev, i);
> +		if (ret < 0)
> +			return ret;
> +
> +		priv->irq[i] = ret;
> +		irq_set_chained_handler_and_data(priv->irq[i],
> +						 sf_gpio_irq_handler, priv);
> +		ret = devm_add_action_or_reset(dev,
> +					       sf_gpio_remove_chained_handler,
> +					       (void *)(unsigned long)priv->irq[i]);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	config.parent = dev;
> +	config.regmap = priv->regmap;
> +	config.ngpio = soc->ngpios;
> +	config.reg_dat_base = GPIO_REGMAP_ADDR(GPIO_IR(0));
> +	config.reg_set_base = GPIO_OR(0);
> +	config.reg_dir_in_base = GPIO_OEN(0);
> +	config.reg_mask_xlate = sf_gpio_reg_mask_xlate;
> +	config.set_config = sf_gpio_set_config;
> +	config.irq_domain = priv->domain;
> +	config.drvdata = priv;
> +
> +	priv->gpio = devm_gpio_regmap_register(dev, &config);

[Severity: High]
Can irq_chip callbacks dereference priv->gpio before it is initialized or
after it has been freed?

sf_gpio_irq_mask(), sf_gpio_irq_unmask(), sf_gpio_irq_request_resources()
and sf_gpio_irq_release_resources() all pass priv->gpio to
gpio_regmap_*_irq(), which dereferences &gpio->gpio_chip.  Because
priv->domain and the parent chained handlers are registered before
devm_gpio_regmap_register(), priv->gpio is NULL until
devm_gpio_regmap_register() returns.  Furthermore, devres unwinds in
reverse order on unbind, so devm_gpio_regmap_unregister() frees priv->gpio
before sf_gpio_remove_chained_handler() and devm_irq_domain_remove() run,
leaving a use-after-free window if an IRQ is masked, unmasked or released
during teardown.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122-sf19a2890-gpio-v3-0-3a4857ebc84a@telaak.dev?part=2

  reply	other threads:[~2026-11-23  1:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  1:37 [PATCH v3 0/2] gpio: Add the Siflower SF19A2890 GPIO controller Joseph Telaak
2026-11-23  1:37 ` Joseph Telaak via B4 Relay
2026-11-23  1:37 ` [PATCH v3 1/2] dt-bindings: gpio: Add " Joseph Telaak
2026-11-23  1:37   ` Joseph Telaak via B4 Relay
2026-11-23  1:45   ` sashiko-bot
2026-11-23  1:37 ` [PATCH v3 2/2] gpio: Add Siflower GPIO controller driver Joseph Telaak
2026-11-23  1:37   ` Joseph Telaak via B4 Relay
2026-11-23  1:49   ` sashiko-bot [this message]
2026-11-23  4:01     ` Joseph Telaak
2026-11-30 21:49       ` Linus Walleij
2026-11-30 22:03         ` Joseph Telaak
2026-11-30 22:06           ` Linus Walleij

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-228534@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=joseph@telaak.dev \
    --cc=linux-gpio@vger.kernel.org \
    --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 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.