* [PATCH] usb: typec: qcom-pmic-typec: Avoid reading uninitialized state on error paths
@ 2026-11-19 17:08 Ian Rogers
2026-11-19 17:15 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2026-11-19 17:08 UTC (permalink / raw)
To: Bryan O'Donoghue, Heikki Krogerus, Greg Kroah-Hartman
Cc: linux-arm-msm, linux-usb, linux-kernel, llvm, Elkin Cruz,
Ian Rogers
In qcom_pmic_typec_port_set_cc(), error paths from regmap_read() and the
default switch branch jump to 'done:', which logs 'currsrc', 'mode', and
'misc' via dev_dbg() and passes uninitialized 'currsrc' into
rp_sel_to_name(), indexing rp_sel_name[] out-of-bounds when dynamic debug
is enabled. Similarly, early error paths in qcom_pmic_typec_port_get_cc()
jump to 'done:' before 'misc', 'attached', '*cc1', and '*cc2' are
initialized.
Return early on error paths in both functions instead of jumping to the
post-success dev_dbg() trace.
Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
-Wconditional-uninitialized enabled; fix and changelog drafted with an AI
coding assistant. Build-tested under LLVM=1 W=1 (-Werror) and
-Wconditional-uninitialized; not tested on Qualcomm PMIC Type-C hardware.
Fixes: a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
Signed-off-by: Ian Rogers <irogers@google.com>
---
.../typec/tcpm/qcom/qcom_pmic_typec_port.c | 25 +++++++++----------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
index b2ad31e85b5e..a1595b8b53e7 100644
--- a/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
+++ b/drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
@@ -372,14 +372,12 @@ static int qcom_pmic_typec_port_get_cc(struct tcpc_dev *tcpc,
ret = regmap_read(pmic_typec_port->regmap,
pmic_typec_port->base + TYPEC_MISC_STATUS_REG, &misc);
if (ret)
- goto done;
+ return ret;
attached = !!(misc & CC_ATTACHED);
- if (pmic_typec_port->debouncing_cc) {
- ret = -EBUSY;
- goto done;
- }
+ if (pmic_typec_port->debouncing_cc)
+ return -EBUSY;
*cc1 = TYPEC_CC_OPEN;
*cc2 = TYPEC_CC_OPEN;
@@ -392,7 +390,7 @@ static int qcom_pmic_typec_port_get_cc(struct tcpc_dev *tcpc,
pmic_typec_port->base + TYPEC_SRC_STATUS_REG,
&val);
if (ret)
- goto done;
+ return ret;
switch (val & DETECTED_SRC_TYPE_MASK) {
case AUDIO_ACCESS_RA_RA:
val = TYPEC_CC_RA;
@@ -417,7 +415,7 @@ static int qcom_pmic_typec_port_get_cc(struct tcpc_dev *tcpc,
pmic_typec_port->base + TYPEC_SNK_STATUS_REG,
&val);
if (ret)
- goto done;
+ return ret;
switch (val & DETECTED_SNK_TYPE_MASK) {
case SNK_RP_STD:
val = TYPEC_CC_RP_DEF;
@@ -472,7 +470,7 @@ static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc,
pmic_typec_port->base + TYPEC_MISC_STATUS_REG,
&misc);
if (ret)
- goto done;
+ goto err_unlock;
mode = EN_SRC_ONLY;
@@ -496,7 +494,7 @@ static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc,
default:
dev_warn(dev, "unexpected set_cc %d\n", cc);
ret = -EINVAL;
- goto done;
+ goto err_unlock;
}
if (mode == EN_SRC_ONLY) {
@@ -504,14 +502,11 @@ static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc,
pmic_typec_port->base + TYPEC_CURRSRC_CFG_REG,
currsrc);
if (ret)
- goto done;
+ goto err_unlock;
}
pmic_typec_port->cc = cc;
qcom_pmic_set_cc_debounce(pmic_typec_port);
- ret = 0;
-
-done:
spin_unlock_irqrestore(&pmic_typec_port->lock, flags);
dev_dbg(dev, "set_cc: currsrc=%x %s mode %s debounce %d attached %d cc=%s\n",
@@ -520,6 +515,10 @@ static int qcom_pmic_typec_port_set_cc(struct tcpc_dev *tcpc,
pmic_typec_port->debouncing_cc, !!(misc & CC_ATTACHED),
misc_to_cc(misc));
+ return 0;
+
+err_unlock:
+ spin_unlock_irqrestore(&pmic_typec_port->lock, flags);
return ret;
}
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] usb: typec: qcom-pmic-typec: Avoid reading uninitialized state on error paths
2026-11-19 17:08 [PATCH] usb: typec: qcom-pmic-typec: Avoid reading uninitialized state on error paths Ian Rogers
@ 2026-11-19 17:15 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 17:15 UTC (permalink / raw)
To: Ian Rogers; +Cc: linux-usb
> In qcom_pmic_typec_port_set_cc(), error paths from regmap_read() and the
> default switch branch jump to 'done:', which logs 'currsrc', 'mode', and
> 'misc' via dev_dbg() and passes uninitialized 'currsrc' into
> rp_sel_to_name(), indexing rp_sel_name[] out-of-bounds when dynamic debug
> is enabled. Similarly, early error paths in qcom_pmic_typec_port_get_cc()
> jump to 'done:' before 'misc', 'attached', '*cc1', and '*cc2' are
> initialized.
>
> Return early on error paths in both functions instead of jumping to the
> post-success dev_dbg() trace.
>
> Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
> -Wconditional-uninitialized enabled; fix and changelog drafted with an AI
> coding assistant. Build-tested under LLVM=1 W=1 (-Werror) and
> -Wconditional-uninitialized; not tested on Qualcomm PMIC Type-C hardware.
>
> Fixes: a4422ff22142 ("usb: typec: qcom: Add Qualcomm PMIC Type-C driver")
> Signed-off-by: Ian Rogers <irogers@google.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119170853.1529676-1-irogers@google.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 17:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 17:08 [PATCH] usb: typec: qcom-pmic-typec: Avoid reading uninitialized state on error paths Ian Rogers
2026-11-19 17:15 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox