From: Ian Rogers <irogers@google.com>
To: Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Elkin Cruz <elkin@google.com>,
Ian Rogers <irogers@google.com>,
stable@vger.kernel.org
Subject: [PATCH v2] usb: typec: hd3ss3220: Propagate regmap_read() errors from attached-state check
Date: Sat, 21 Nov 2026 20:53:13 -0800 [thread overview]
Message-ID: <20261122045313.18372-1-irogers@google.com> (raw)
hd3ss3220_get_attached_state() has return type 'enum usb_role' (an
unsigned enum) yet returns negative regmap_read() error codes directly.
Neither hd3ss3220_set_role() nor output_poll_execute() checks for errors;
on a transient I2C failure (such as -EIO, cast to 0xfffffffb),
hd3ss3220_set_role() passes the bogus value to usb_role_switch_set_role()
and disables VBUS power. On role-switch providers without a .get callback
(where sw->role caches the value passed to usb_role_switch_set_role()),
reading /sys/class/usb_role/*/role subsequently indexes usb_roles[role]
out-of-bounds.
Return an int status from hd3ss3220_get_attached_state() and
hd3ss3220_set_role(), pass the resolved enum usb_role via an output
pointer, leave the current role and VBUS state unchanged on I2C read
errors, and propagate errors to hd3ss3220_probe() and hd3ss3220_irq().
Found via an x86_64 LLVM=1 (Clang 21.1.8) allyesconfig audit with
-Wimplicit-int-enum-cast enabled; fix and changelog drafted with an AI
coding assistant. Build-tested under LLVM=1 W=1 (-Werror) and
-Wimplicit-int-enum-cast; not tested on TI HD3SS3220 hardware.
Fixes: 1c48c759ef4b ("usb: typec: driver for TI HD3SS3220 USB Type-C DRP port controller")
Cc: stable@vger.kernel.org
Signed-off-by: Ian Rogers <irogers@google.com>
---
Notes:
v2:
- Propagate regmap_read() errors out of hd3ss3220_set_role() to
hd3ss3220_probe() and hd3ss3220_irq(), and test
!hd3ss3220_get_attached_state() in output_poll_execute() (Greg
Kroah-Hartman).
- Add Cc: stable@vger.kernel.org (Heikki Krogerus).
v1: https://lore.kernel.org/r/20261119170650.1521609-1-irogers@google.com
drivers/usb/typec/hd3ss3220.c | 38 ++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 12 deletions(-)
diff --git a/drivers/usb/typec/hd3ss3220.c b/drivers/usb/typec/hd3ss3220.c
index 60d6de9ba339..bdd4eaeca753 100644
--- a/drivers/usb/typec/hd3ss3220.c
+++ b/drivers/usb/typec/hd3ss3220.c
@@ -163,10 +163,10 @@ static int hd3ss3220_set_source_pref(struct hd3ss3220 *hd3ss3220, int prefer_rol
src_pref);
}
-static enum usb_role hd3ss3220_get_attached_state(struct hd3ss3220 *hd3ss3220)
+static int hd3ss3220_get_attached_state(struct hd3ss3220 *hd3ss3220,
+ enum usb_role *attached_state)
{
unsigned int reg_val;
- enum usb_role attached_state;
int ret;
ret = regmap_read(hd3ss3220->regmap, HD3SS3220_REG_CN_STAT_CTRL,
@@ -176,17 +176,17 @@ static enum usb_role hd3ss3220_get_attached_state(struct hd3ss3220 *hd3ss3220)
switch (reg_val & HD3SS3220_REG_CN_STAT_CTRL_ATTACHED_STATE_MASK) {
case HD3SS3220_REG_CN_STAT_CTRL_AS_DFP:
- attached_state = USB_ROLE_HOST;
+ *attached_state = USB_ROLE_HOST;
break;
case HD3SS3220_REG_CN_STAT_CTRL_AS_UFP:
- attached_state = USB_ROLE_DEVICE;
+ *attached_state = USB_ROLE_DEVICE;
break;
default:
- attached_state = USB_ROLE_NONE;
+ *attached_state = USB_ROLE_NONE;
break;
}
- return attached_state;
+ return 0;
}
static int hd3ss3220_try_role(struct typec_port *port, int role)
@@ -229,9 +229,14 @@ static void hd3ss3220_regulator_control(struct hd3ss3220 *hd3ss3220, bool on)
hd3ss3220->vbus_enabled = on;
}
-static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220)
+static int hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220)
{
- enum usb_role role_state = hd3ss3220_get_attached_state(hd3ss3220);
+ enum usb_role role_state;
+ int ret;
+
+ ret = hd3ss3220_get_attached_state(hd3ss3220, &role_state);
+ if (ret < 0)
+ return ret;
usb_role_switch_set_role(hd3ss3220->role_sw, role_state);
@@ -250,6 +255,8 @@ static void hd3ss3220_set_role(struct hd3ss3220 *hd3ss3220)
hd3ss3220_regulator_control(hd3ss3220, role_state == USB_ROLE_HOST);
hd3ss3220->role_state = role_state;
+
+ return 0;
}
static void output_poll_execute(struct work_struct *work)
@@ -258,9 +265,10 @@ static void output_poll_execute(struct work_struct *work)
struct hd3ss3220 *hd3ss3220 = container_of(delayed_work,
struct hd3ss3220,
output_poll_work);
- enum usb_role role_state = hd3ss3220_get_attached_state(hd3ss3220);
+ enum usb_role role_state;
- if (hd3ss3220->role_state != role_state)
+ if (!hd3ss3220_get_attached_state(hd3ss3220, &role_state) &&
+ hd3ss3220->role_state != role_state)
hd3ss3220_set_role(hd3ss3220);
schedule_delayed_work(&hd3ss3220->output_poll_work, HZ);
@@ -270,7 +278,10 @@ static irqreturn_t hd3ss3220_irq(struct hd3ss3220 *hd3ss3220)
{
int err;
- hd3ss3220_set_role(hd3ss3220);
+ err = hd3ss3220_set_role(hd3ss3220);
+ if (err < 0)
+ return IRQ_NONE;
+
err = regmap_write_bits(hd3ss3220->regmap, HD3SS3220_REG_CN_STAT_CTRL,
HD3SS3220_REG_CN_STAT_CTRL_INT_STATUS,
HD3SS3220_REG_CN_STAT_CTRL_INT_STATUS);
@@ -501,7 +512,10 @@ static int hd3ss3220_probe(struct i2c_client *client)
if (ret < 0)
goto err_unreg_port;
- hd3ss3220_set_role(hd3ss3220);
+ ret = hd3ss3220_set_role(hd3ss3220);
+ if (ret < 0)
+ goto err_unreg_port;
+
ret = regmap_read(hd3ss3220->regmap, HD3SS3220_REG_CN_STAT_CTRL, &data);
if (ret < 0)
goto err_unreg_port;
--
2.56.1.750.gf70dc682cf-goog
reply other threads:[~2026-11-22 4:53 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=20261122045313.18372-1-irogers@google.com \
--to=irogers@google.com \
--cc=elkin@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=stable@vger.kernel.org \
/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