From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Ian Rogers <irogers@google.com>
Cc: Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
Elkin Cruz <elkin@google.com>
Subject: Re: [PATCH] usb: typec: qcom-pmic-typec: Avoid reading uninitialized state on error paths
Date: Fri, 20 Nov 2026 16:07:47 +0100 [thread overview]
Message-ID: <awBiQ0S1hYnm-ngo@black.igk.intel.com> (raw)
In-Reply-To: <20261119170853.1529676-1-irogers@google.com>
On Thu, Nov 19, 2026 at 09:08:53AM -0800, Ian Rogers wrote:
> 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>
No stable here either?
Thanks,
> ---
> .../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
--
heikki
prev parent reply other threads:[~2026-11-20 15:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 17:08 Ian Rogers
2026-11-20 15:07 ` Heikki Krogerus [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=awBiQ0S1hYnm-ngo@black.igk.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=bryan.odonoghue@linaro.org \
--cc=elkin@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=irogers@google.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=llvm@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
all inboxes | Powered by JetHome®