usb_role_switch_is_parent() was walking up to the parent node and checking
for the "usb-role-switch" property regardless of the type of the passed
fwnode. This could cause unrelated device nodes to be probed as potential
role switch parent, leading to spurious matches and "-EPROBE_DEFER" being
returned infinitely.
Till now only Type-B connector node will have a parent node which may
present "usb-role-switch" property and register the role switch device.
For Type-C connector node, its parent node will always be a Type-C chip
device which will never register the role switch device. However, it may
still present a non-boolean "usb-role-switch = <&usb_controller>" property
for historical compatibility.
So restrict the helper to only operate on Type-B connector when attempting
to get the role switch from parent node.
Fixes: 6fadd72943b8 ("usb: roles: get usb-role-switch from parent")
Cc: stable@vger.kernel.org
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
Changes in v2:
- new patch
---
drivers/usb/roles/class.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index b8e28ceca51e..edec139b68b5 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -139,9 +139,14 @@ static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const cha
static struct usb_role_switch *
usb_role_switch_is_parent(struct fwnode_handle *fwnode)
{
- struct fwnode_handle *parent = fwnode_get_parent(fwnode);
+ struct fwnode_handle *parent;
struct device *dev;
+ if (!fwnode_device_is_compatible(fwnode, "usb-b-connector"))
+ return NULL;
+
+ parent = fwnode_get_parent(fwnode);
+
if (!fwnode_property_present(parent, "usb-role-switch")) {
fwnode_handle_put(parent);
return NULL;
--
2.34.1
From: Frank Li (AI-BOT) <frank.li@nxp.com>
> if (!fwnode_device_is_compatible(fwnode, "usb-b-connector"))
> return NULL;
AI: Nit: inconsistent indentation. Should use a single tab, not two spaces.
Use '\t' for the return statement to match kernel style.
> parent = fwnode_get_parent(fwnode);
>
> if (!fwnode_property_present(parent, "usb-role-switch")) {
AI: Missing NULL check on parent before passing to fwnode_property_present().
If fwnode_get_parent() returns NULL, the next call will dereference it.
Add: if (!parent) return NULL;
Frank
Hi Frank,
On Mon, Mar 09, 2026 at 03:48:59PM -0400, Frank Li wrote:
> From: Frank Li (AI-BOT) <frank.li@nxp.com>
>
> > if (!fwnode_device_is_compatible(fwnode, "usb-b-connector"))
> > return NULL;
>
> AI: Nit: inconsistent indentation. Should use a single tab, not two spaces.
> Use '\t' for the return statement to match kernel style.
>
> > parent = fwnode_get_parent(fwnode);
> >
> > if (!fwnode_property_present(parent, "usb-role-switch")) {
>
> AI: Missing NULL check on parent before passing to fwnode_property_present().
> If fwnode_get_parent() returns NULL, the next call will dereference it.
> Add: if (!parent) return NULL;
Ignore this!
Both above AI reported issues are false-alarm. Please refine the AI-BOT.
And the message he sent didn't reach to me (I'm not in --to list). So the
issue may not be resolved timely.
Thanks,
Xu Yang
Le 09/03/2026 à 08:43, Xu Yang a écrit :
> usb_role_switch_is_parent() was walking up to the parent node and checking
> for the "usb-role-switch" property regardless of the type of the passed
> fwnode. This could cause unrelated device nodes to be probed as potential
> role switch parent, leading to spurious matches and "-EPROBE_DEFER" being
> returned infinitely.
>
> Till now only Type-B connector node will have a parent node which may
> present "usb-role-switch" property and register the role switch device.
> For Type-C connector node, its parent node will always be a Type-C chip
> device which will never register the role switch device. However, it may
> still present a non-boolean "usb-role-switch = <&usb_controller>" property
> for historical compatibility.
>
> So restrict the helper to only operate on Type-B connector when attempting
> to get the role switch from parent node.
>
> Fixes: 6fadd72943b8 ("usb: roles: get usb-role-switch from parent")
> Cc: stable@vger.kernel.org
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
>
> ---
> Changes in v2:
> - new patch
> ---
> drivers/usb/roles/class.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
> index b8e28ceca51e..edec139b68b5 100644
> --- a/drivers/usb/roles/class.c
> +++ b/drivers/usb/roles/class.c
> @@ -139,9 +139,14 @@ static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const cha
> static struct usb_role_switch *
> usb_role_switch_is_parent(struct fwnode_handle *fwnode)
> {
> - struct fwnode_handle *parent = fwnode_get_parent(fwnode);
> + struct fwnode_handle *parent;
> struct device *dev;
>
> + if (!fwnode_device_is_compatible(fwnode, "usb-b-connector"))
> + return NULL;
> +
> + parent = fwnode_get_parent(fwnode);
> +
> if (!fwnode_property_present(parent, "usb-role-switch")) {
> fwnode_handle_put(parent);
> return NULL;
Tested-by: Arnaud Ferraris <arnaud.ferraris@collabora.com>
Cheers,
Arnaud
© 2016 - 2026 Red Hat, Inc.