All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Elkin Cruz" <elkin@google.com>
Cc: linux-gpio@vger.kernel.org
Subject: Re: [PATCH 2/2] pinctrl: tegra: Add register bank bounds checks
Date: Wed, 25 Nov 2026 22:51:57 +0000	[thread overview]
Message-ID: <sashiko-outbox-234296@kernel.org> (raw)
In-Reply-To: <20261125222549.1447825-3-elkin@google.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] pinctrl: tegra: ZERO_SIZE_PTR dereference in
  tegra_pinctrl_resume() [1]
--

commit 21e28d7f25582cfa017ebe0451bae69737c000a5
Author: Elkin Cruz <elkin@google.com>

pinctrl: tegra: Add register bank bounds checks

This commit adds bounds checks against pmx->nbanks in pmx_readl(),
pmx_writel(), and tegra_pinconf_reg() before indexing pmx->regs.

> diff --git a/drivers/pinctrl/tegra/pinctrl-tegra.c b/drivers/pinctrl/tegra/pinctrl-tegra.c
> index 51684c5dda349..c0b584d37a8e0 100644
> --- a/drivers/pinctrl/tegra/pinctrl-tegra.c
> +++ b/drivers/pinctrl/tegra/pinctrl-tegra.c
> @@ -30,11 +30,17 @@
>  
>  static inline u32 pmx_readl(struct tegra_pmx *pmx, u32 bank, u32 reg)
>  {
> +	if (WARN_ON_ONCE(bank >= pmx->nbanks))
> +		return 0;
> +
>  	return readl(pmx->regs[bank] + reg);
>  }

[Severity: High]
This problem wasn't introduced by this patch, but can tegra_pinctrl_resume()
dereference a ZERO_SIZE_PTR via pmx->regs[0] [1]?

If the device tree node omits the reg property, tegra_pinctrl_probe() finds
no IORESOURCE_MEM resources, sets pmx->nbanks to 0, and allocates pmx->regs
with devm_kcalloc(..., 0, ...), which returns ZERO_SIZE_PTR and lets probe
succeed.  On resume, tegra_pinctrl_resume() skips the bank loop when
pmx->nbanks is 0, but still unconditionally reads from pmx->regs[0]:

drivers/pinctrl/tegra/pinctrl-tegra.c:tegra_pinctrl_resume() {
	...
	for (i = 0; i < pmx->nbanks; i++) {
		...
	}

	/* flush all the prior writes */
	readl_relaxed(pmx->regs[0]);
	...
}

Failing tegra_pinctrl_probe() when pmx->nbanks is 0 (or guarding the dummy
read in tegra_pinctrl_resume()) would avoid this crash.

[1] https://sashiko.dev/#/bug/linux-dc81d6b3-2c40-4253-b0f9-393c796e6adb

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125222549.1447825-1-elkin@google.com?part=2

      reply	other threads:[~2026-11-25 22:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 22:25 [PATCH 0/2] pinctrl: tegra: fix Tegra186 AON bank index and add bank bounds checks Elkin Cruz
2026-11-25 22:25 ` [PATCH 1/2] pinctrl: tegra186: Fix register bank for AON drive pin groups Elkin Cruz
2026-11-25 22:25 ` [PATCH 2/2] pinctrl: tegra: Add register bank bounds checks Elkin Cruz
2026-11-25 22:51   ` sashiko-bot [this message]

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-234296@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=elkin@google.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.