From: Stepan Ionichev <sozdayvek@gmail.com>
To: andy@kernel.org
Cc: mika.westerberg@linux.intel.com, linusw@kernel.org,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
sozdayvek@gmail.com
Subject: [PATCH] pinctrl: intel: zero-initialize capability_offset[] in probe
Date: Fri, 15 May 2026 20:00:49 +0500 [thread overview]
Message-ID: <20260515150049.33761-1-sozdayvek@gmail.com> (raw)
intel_pinctrl_probe() declares a per-community capability_offset[]
array on the stack and only writes the slots whose CAPLIST entries
the device actually advertises:
unsigned short capability_offset[6];
...
do {
value = readl(regs + offset);
switch ((value & CAPLIST_ID_MASK) >> CAPLIST_ID_SHIFT) {
case CAPLIST_ID_GPIO_HW_INFO:
capability_offset[CAPLIST_ID_GPIO_HW_INFO] = offset;
break;
case CAPLIST_ID_PWM:
capability_offset[CAPLIST_ID_PWM] = offset;
break;
...
default:
break;
}
...
} while (offset);
...
ret = intel_pinctrl_probe_pwm(pctrl, community,
capability_offset[CAPLIST_ID_PWM]);
If a community does not advertise a PWM capability, the loop never
writes capability_offset[CAPLIST_ID_PWM] and the call to
intel_pinctrl_probe_pwm() reads an indeterminate stack value.
intel_pinctrl_probe_pwm() computes the PWM register base before it
checks PINCTRL_FEATURE_PWM:
void __iomem *base = community->regs + capability_offset + 4;
...
if (!(community->features & PINCTRL_FEATURE_PWM))
return 0;
so the base = community->regs + capability_offset + 4 expression is
evaluated using the uninitialized value on every probe for any
community that does not have CAPLIST_ID_PWM. The result is never
dereferenced when the PWM feature flag is clear, but reading an
indeterminate stack object is undefined behaviour by C, and KMSAN /
UBSAN report it at probe time.
Default the whole array to zero at declaration so unused slots are
defined (community->regs + 4) instead of indeterminate.
Fixes: 340bba73c545 ("pinctrl: intel: Improve capability support")
Signed-off-by: Stepan Ionichev <sozdayvek@gmail.com>
---
drivers/pinctrl/intel/pinctrl-intel.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
index 97bf5ec78..4fb4a3dab 100644
--- a/drivers/pinctrl/intel/pinctrl-intel.c
+++ b/drivers/pinctrl/intel/pinctrl-intel.c
@@ -1601,7 +1601,7 @@ int intel_pinctrl_probe(struct platform_device *pdev,
for (i = 0; i < pctrl->ncommunities; i++) {
struct intel_community *community = &pctrl->communities[i];
- unsigned short capability_offset[6];
+ unsigned short capability_offset[6] = { };
void __iomem *regs;
u32 revision;
u32 offset;
--
2.43.0
reply other threads:[~2026-05-15 15:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260515150049.33761-1-sozdayvek@gmail.com \
--to=sozdayvek@gmail.com \
--cc=andy@kernel.org \
--cc=linusw@kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
/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