ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pablo Mazzini" <pmazzini@gmail.com>
Cc: linux-sunxi@lists.linux.dev
Subject: Re: [PATCH v2 04/11] pinctrl: sunxi: add Allwinner B288 pin controller driver
Date: Sun, 27 Sep 2026 15:26:54 +0000	[thread overview]
Message-ID: <20260927152654.76FE11F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260927151016.186493-5-pmazzini@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] pinctrl: out-of-bounds access and corrupt IRQ mapping due to shifted bank index
- [High] pinctrl: NULL pointer dereference on probe deferral due to global state leak
--

commit c211ae9972d97b1239a013dc4594d43764f7806c
Author: Pablo Mazzini <pmazzini@gmail.com>

    pinctrl: sunxi: add Allwinner B288 pin controller driver

This commit adds pin controller and GPIO support for the Allwinner B288
SoC. It defines 80 pins across ports B, C, D, F, and G, omitting port A
completely.

> diff --git a/drivers/pinctrl/sunxi/pinctrl-sun8i-b288.c b/drivers/pinctrl/sunxi/pinctrl-sun8i-b288.c
> new file mode 100644
> index 0000000000000..98dd4ead4c328
> --- /dev/null
> +++ b/drivers/pinctrl/sunxi/pinctrl-sun8i-b288.c
> @@ -0,0 +1,53 @@

[ ... ]

> +/* PH0 exists only on the BSP's FPGA platform and is omitted. */
> +static const u8 b288_nr_bank_pins[SUNXI_PINCTRL_MAX_BANKS] =
> +/*	  PA  PB  PC  PD  PE  PF  PG */
> +	{  0, 17, 15, 29,  0,  7, 12 };
> +
> +/* Port C has no external interrupts. */
> +static const unsigned int b288_irq_bank_map[] = { 1, 3, 5, 6 };
> +
> +static const u8 b288_irq_bank_muxes[SUNXI_PINCTRL_MAX_BANKS] =
> +/*	  PA  PB  PC  PD  PE  PF  PG */
> +	{  0,  6,  0,  6,  0,  6,  6 };

[Severity: High]
Does this pin layout trigger an out-of-bounds access and corrupt the IRQ
mapping?

Because bank PA has 0 pins, PB (bank 1) is the first bank processed. In
drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c:prepare_function_table(),
last_bank is initialized to 0. When PB is processed, bank > last_bank
(1 > 0) evaluates to true, which erroneously increments irq_bank to 1 for
the first bank instead of 0:

			if (bank > last_bank)
				irq_bank++;

This shifts all logical IRQ banks so PB gets irqbank=1, PD=2, PF=3, and
PG=4. Since b288_irq_bank_map only has 4 elements, processing PG (irqbank=4)
causes sunxi_irq_hw_bank_num() to read out of bounds.

Further, sunxi_pinctrl_build_state() will write out of bounds past the
end of pctl->irq_array:

	int irqnum = func->irqnum + func->irqbank * IRQ_PER_BANK;
	pctl->irq_array[irqnum] = pin->pin.number;

Since func->irqbank evaluates to 4 (which is >= desc->irq_banks), this
causes boot-time memory corruption and breaks IRQ routing for all pins.

> +static struct sunxi_pinctrl_desc b288_pinctrl_data = {
> +	.irq_banks	= ARRAY_SIZE(b288_irq_bank_map),
> +	.irq_bank_map	= b288_irq_bank_map,
> +};
> +
> +static int b288_pinctrl_probe(struct platform_device *pdev)
> +{
> +	return sunxi_pinctrl_dt_table_init(pdev, b288_nr_bank_pins,
> +					   b288_irq_bank_muxes,
> +					   &b288_pinctrl_data, 0);
> +}

[Severity: High]
Does passing this static global struct to the framework leak state on
probe deferral, leading to a NULL pointer dereference?

The b288_pinctrl_data struct is a static global passed to
sunxi_pinctrl_dt_table_init(). Inside init_pins_table(), desc->npins is
unconditionally incremented into the global state:

	desc->npins += pins_per_bank[i];

If sunxi_pinctrl_init_with_flags() subsequently defers probe (e.g., waiting
for a clock or PMIC), desc->npins permanently retains the 80 count. On the
next probe attempt, desc->npins becomes 160.

This causes devm_kcalloc() to allocate 160 descriptors, but only the first 80
are properly initialized with names. The trailing 80 elements retain NULL
pin.name pointers, which causes a crash during re-probe in
prepare_function_table() when iterating over the uninitialized elements:

				if (strcmp(pins[i].pin.name, name))
					continue;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260927151016.186493-1-pmazzini@gmail.com?part=4

  reply	other threads:[~2026-09-27 15:26 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27 15:10 [PATCH v2 00/11] ARM: sunxi: add Allwinner B288 and the PocketBook Verse Pablo Mazzini
2026-09-27 15:10 ` [PATCH v2 01/11] dt-bindings: clock: sun4i-a10-ccu: add Allwinner B288 Pablo Mazzini
2026-09-30 10:08   ` Krzysztof Kozlowski
2026-09-27 15:10 ` [PATCH v2 02/11] clk: sunxi-ng: add Allwinner B288 CCU driver Pablo Mazzini
2026-09-27 15:23   ` sashiko-bot
2026-09-27 15:10 ` [PATCH v2 03/11] dt-bindings: pinctrl: sun4i-a10: add Allwinner B288 Pablo Mazzini
2026-09-27 15:18   ` sashiko-bot
2026-09-27 15:10 ` [PATCH v2 04/11] pinctrl: sunxi: add Allwinner B288 pin controller driver Pablo Mazzini
2026-09-27 15:26   ` sashiko-bot [this message]
2026-09-27 15:10 ` [PATCH v2 05/11] dt-bindings: rtc: sun6i-a31: add Allwinner B288 Pablo Mazzini
2026-09-27 15:17   ` sashiko-bot
2026-09-30 10:10   ` Krzysztof Kozlowski
2026-09-30 10:47     ` Pablo Mazzini
2026-09-27 15:10 ` [PATCH v2 06/11] rtc: sun6i: add Allwinner B288 compatible Pablo Mazzini
2026-09-27 15:18   ` sashiko-bot
2026-09-27 15:10 ` [PATCH v2 08/11] dt-bindings: mmc: sun4i-a10-mmc: add Allwinner B288 Pablo Mazzini
2026-09-30 10:15   ` Krzysztof Kozlowski
2026-09-30 16:04   ` Ulf Hansson
2026-09-27 15:10 ` [PATCH v2 09/11] dt-bindings: interrupt-controller: add Allwinner B288 NMI Pablo Mazzini
2026-09-30 10:17   ` Krzysztof Kozlowski
2026-09-27 15:10 ` [PATCH v2 10/11] dt-bindings: arm: sunxi: add PocketBook Verse Pablo Mazzini
2026-09-27 15:27   ` sashiko-bot
2026-09-27 15:10 ` [PATCH v2 11/11] ARM: sunxi: add B288 and the PocketBook Verse board Pablo Mazzini
2026-09-27 15:29   ` sashiko-bot
2026-09-30 12:01   ` Andre Przywara
2026-09-30 17:52     ` Pablo Mazzini

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=20260927152654.76FE11F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=pmazzini@gmail.com \
    --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