From: Xu Yang <xu.yang_2@oss.nxp.com>
To: Peter Chen <peter.chen@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev, jun.li@nxp.com
Subject: [PATCH v2] usb: chipidea: otg: fix invalid role name print when no current role
Date: Mon, 7 Sep 2026 18:16:43 +0800 [thread overview]
Message-ID: <20260907101643.2844296-1-xu.yang_2@oss.nxp.com> (raw)
From: Xu Yang <xu.yang_2@nxp.com>
ci_handle_id_switch() prints the role transition via ci_role(ci)->name
for the current role, but when ci->role is CI_ROLE_END (no role
assigned yet), ci_role(ci) call BUG_ON() and return ci->roles[CI_ROLE_END]
which will cause invalid memory access in the debug print.
This can happen if ci_role_start() fails during a role switch, since
ci_role_stop() has already set ci->role to CI_ROLE_END.
Fix it by printing "none" instead of dereferencing ci_role(ci)->name
when ci->role is not a valid role.
Fixes: cbec6bd55a45 ("usb: chipidea: move otg related things to otg file")
Cc: stable@vger.kernel.org
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
Changes in v2:
- improve commit message
- use " >= " sign
---
drivers/usb/chipidea/otg.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c
index fecc7d7e2f0d..5eb3b32c2e87 100644
--- a/drivers/usb/chipidea/otg.c
+++ b/drivers/usb/chipidea/otg.c
@@ -179,7 +179,8 @@ void ci_handle_id_switch(struct ci_hdrc *ci)
role = ci_otg_role(ci);
if (role != ci->role) {
dev_dbg(ci->dev, "switching from %s to %s\n",
- ci_role(ci)->name, ci->roles[role]->name);
+ ci->role >= CI_ROLE_END ? "none" : ci_role(ci)->name,
+ ci->roles[role]->name);
if (ci->vbus_active && ci->role == CI_ROLE_GADGET)
/*
--
2.34.1
reply other threads:[~2026-09-07 10:12 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=20260907101643.2844296-1-xu.yang_2@oss.nxp.com \
--to=xu.yang_2@oss.nxp.com \
--cc=gregkh@linuxfoundation.org \
--cc=imx@lists.linux.dev \
--cc=jun.li@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=peter.chen@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