[PATCH] USB: of: filter disabled device node

Zhengqiao Xia posted 1 patch 1 week, 2 days ago
drivers/usb/core/of.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] USB: of: filter disabled device node
Posted by Zhengqiao Xia 1 week, 2 days ago
We should not point the of_node of a USB device to a disabled devicetree
node. Otherwise, the interface under this USB device will not be able
to register.

Signed-off-by: Zhengqiao Xia <jerry.xzq@gmail.com>
---
 drivers/usb/core/of.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
index 763e4122ed5b3..6bb577e711811 100644
--- a/drivers/usb/core/of.c
+++ b/drivers/usb/core/of.c
@@ -31,6 +31,9 @@ struct device_node *usb_of_get_device_node(struct usb_device *hub, int port1)
 		if (of_property_read_u32(node, "reg", &reg))
 			continue;
 
+		if (!of_device_is_available(node))
+			continue;
+
 		if (reg == port1)
 			return node;
 	}
-- 
2.34.1
Re: [PATCH] USB: of: filter disabled device node
Posted by Greg KH 1 week, 2 days ago
On Sat, Nov 22, 2025 at 07:25:39PM +0800, Zhengqiao Xia wrote:
> We should not point the of_node of a USB device to a disabled devicetree
> node. Otherwise, the interface under this USB device will not be able
> to register.

Why would a USB device point to a disabled device tree node?  Shouldn't
the device tree be fixed instead?

thanks,

greg k-h
Re: [PATCH] USB: of: filter disabled device node
Posted by jerry xzq 1 week, 2 days ago
On Sat, Nov 22, 2025 at 7:32 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Sat, Nov 22, 2025 at 07:25:39PM +0800, Zhengqiao Xia wrote:
> > We should not point the of_node of a USB device to a disabled devicetree
> > node. Otherwise, the interface under this USB device will not be able
> > to register.
>
> Why would a USB device point to a disabled device tree node?  Shouldn't
> the device tree be fixed instead?

According to your suggestion, when a USB device is directly connected
to a USB port,
we should delete the unused USB hub node instead of disabling it?

>
> thanks,
>
> greg k-h

thanks
Re: [PATCH] USB: of: filter disabled device node
Posted by Greg KH 1 week, 2 days ago
On Sat, Nov 22, 2025 at 07:49:02PM +0800, jerry xzq wrote:
> On Sat, Nov 22, 2025 at 7:32 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> >
> > On Sat, Nov 22, 2025 at 07:25:39PM +0800, Zhengqiao Xia wrote:
> > > We should not point the of_node of a USB device to a disabled devicetree
> > > node. Otherwise, the interface under this USB device will not be able
> > > to register.
> >
> > Why would a USB device point to a disabled device tree node?  Shouldn't
> > the device tree be fixed instead?
> 
> According to your suggestion, when a USB device is directly connected
> to a USB port,
> we should delete the unused USB hub node instead of disabling it?

Why are you using device tree to describe USB devices at all?  What is
the root problem here that you are trying to solve?

The use of USB in DT should be _VERY_ limited, if at all.  You should
only do so for very good reasons in very limited situations.  If this
starts to get abused, we'll just have to rip it all out :(

thanks,

greg k-h
Re: [PATCH] USB: of: filter disabled device node
Posted by jerry xzq 1 week, 2 days ago
On Sat, Nov 22, 2025 at 8:32 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Sat, Nov 22, 2025 at 07:49:02PM +0800, jerry xzq wrote:
> > On Sat, Nov 22, 2025 at 7:32 PM Greg KH <gregkh@linuxfoundation.org> wrote:
> > >
> > > On Sat, Nov 22, 2025 at 07:25:39PM +0800, Zhengqiao Xia wrote:
> > > > We should not point the of_node of a USB device to a disabled devicetree
> > > > node. Otherwise, the interface under this USB device will not be able
> > > > to register.
> > >
> > > Why would a USB device point to a disabled device tree node?  Shouldn't
> > > the device tree be fixed instead?
> >
> > According to your suggestion, when a USB device is directly connected
> > to a USB port,
> > we should delete the unused USB hub node instead of disabling it?
>
> Why are you using device tree to describe USB devices at all?  What is
> the root problem here that you are trying to solve?

Our device follows a public board that has a USB hub, which is
described in dtsi as a USB hub node.
However, our device only has a USB device, not a USB hub, so I
disabled the USB hub node in our device's DTS.
&xhci3 {
        status = "okay";

        /* 2.x hub on port 1 */
        usb_hub_2_x: hub@1 {
                compatible = "usbbda,5411";
                reg = <1>;
                vdd-supply = <&pp3300_s3>;
                peer-hub = <&usb_hub_3_x>;

----->         status = "disabled";

                ports {
                        #address-cells = <1>;
                        #size-cells = <0>;
                        port@1 {
                                reg = <1>;
                                usb_hub_dsp1_hs: endpoint { };
                        };
                        port@2 {
                                reg = <2>;
                                usb_hub_dsp2_hs: endpoint { };
                        };
                        port@3 {
                                reg = <3>;
                                usb_hub_dsp3_hs: endpoint { };
                        };
                        port@4 {
                                reg = <4>;

                                /* On-board WWAN card */
                                usb_hub_dsp4_hs: endpoint { };
                        };
                };
        };
Then, during use, it was discovered that the LTE device's of_node
pointed to the hub(hub@1).
However, due to the existence of this piece of code,  USB interface
cannot be registered.

if (intf->dev.of_node &&
!of_device_is_available(intf->dev.of_node)) {
dev_info(&dev->dev, "skipping disabled interface %d\n",
intf->cur_altsetting->desc.bInterfaceNumber);
continue;
}

When the upgrade program for an LTE device calls the USB character device,
because this LTE interface was not registered, a null pointer
exception was encountered, causing a restart.

please refer to
https://lore.kernel.org/all/20251114141821.416835-1-xiazhengqiao@huaqin.corp-partner.google.com/

>
> The use of USB in DT should be _VERY_ limited, if at all.  You should
> only do so for very good reasons in very limited situations.  If this
> starts to get abused, we'll just have to rip it all out :(
>
> thanks,
>
> greg k-h

thanks.
Re: [PATCH] USB: of: filter disabled device node
Posted by Greg KH 1 week, 2 days ago
On Sat, Nov 22, 2025 at 07:25:39PM +0800, Zhengqiao Xia wrote:
> We should not point the of_node of a USB device to a disabled devicetree
> node. Otherwise, the interface under this USB device will not be able
> to register.
> 
> Signed-off-by: Zhengqiao Xia <jerry.xzq@gmail.com>

Also, gmail.com is not a company email :)
Re: [PATCH] USB: of: filter disabled device node
Posted by Greg KH 1 week, 2 days ago
On Sat, Nov 22, 2025 at 07:25:39PM +0800, Zhengqiao Xia wrote:
> We should not point the of_node of a USB device to a disabled devicetree
> node. Otherwise, the interface under this USB device will not be able
> to register.
> 
> Signed-off-by: Zhengqiao Xia <jerry.xzq@gmail.com>
> ---
>  drivers/usb/core/of.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
> index 763e4122ed5b3..6bb577e711811 100644
> --- a/drivers/usb/core/of.c
> +++ b/drivers/usb/core/of.c
> @@ -31,6 +31,9 @@ struct device_node *usb_of_get_device_node(struct usb_device *hub, int port1)
>  		if (of_property_read_u32(node, "reg", &reg))
>  			continue;
>  
> +		if (!of_device_is_available(node))
> +			continue;
> +
>  		if (reg == port1)
>  			return node;
>  	}
> -- 
> 2.34.1
> 
> 

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- This looks like a new version of a previously submitted patch, but you
  did not list below the --- line any changes from the previous version.
  Please read the section entitled "The canonical patch format" in the
  kernel file, Documentation/process/submitting-patches.rst for what
  needs to be done here to properly describe this.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot