[PATCH] usb: typec: qcom-pmic-typec: Avoid reading uninitialized state on error paths

From: Ian Rogers

Date: Thu Nov 19 2026 - 12:09:30 EST


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@xxxxxxxxxx>
---
.../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