LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Peter Chen <peter.chen@nxp.com>
To: "Måns Rullgård" <mans@mansr.com>,
	"Marek Szyprowski" <m.szyprowski@samsung.com>
Cc: "linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-samsung-soc@vger.kernel.org" 
	<linux-samsung-soc@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
	Markus Reichl <m.reichl@fivetechno.de>,
	Krzysztof Kozlowski <krzk@kernel.org>
Subject: RE: [PATCH v3] usb: core: verify devicetree nodes for USB devices
Date: Fri, 10 May 2019 03:10:17 +0000	[thread overview]
Message-ID: <VI1PR04MB5327AD56CA772284DFE663D08B0C0@VI1PR04MB5327.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <yw1xlfzfv4ol.fsf@mansr.com>

 
> 
> Marek Szyprowski <m.szyprowski@samsung.com> writes:
> 
> > Commit 69bec7259853 ("USB: core: let USB device know device node")
> > added support for attaching devicetree node for USB devices. The
> > mentioned commit however identifies the given USB device node only by the 'reg'
> > property in the host controller children nodes. The USB device node
> > however also has to have a 'compatible' property as described in
> > Documentation/devicetree/bindings/usb/usb-device.txt. Lack for the
> > 'compatible' property check might result in assigning a devicetree
> > node, which is not intended to be the proper node for the given USB device.
> >
> > This is important especially when USB host controller has child-nodes
> > for other purposes. For example, Exynos EHCI and OHCI drivers already
> > define child-nodes for each physical root hub port and assigns
> > respective PHY controller and parameters for them. Those binding
> > predates support for USB devicetree nodes.
> >
> > Checking for the proper compatibility string allows to mitigate the
> > conflict between USB device devicetree nodes and the bindings for USB
> > controllers with child nodes. It also fixes the side-effect of the
> > other commits, like 01fdf179f4b0 ("usb: core: skip interfaces disabled
> > in devicetree"), which incorrectly disables some devices on Exynos
> > based boards.
> >

Hi Marek,

The purpose of your patch is do not set of_node for device under USB controller, right?
I do not understand how 01fdf179f4b0 affect your boards, some nodes under
the USB controller with status is not "okay", but still want to be enumerated?

Peter

> > Reported-by: Markus Reichl <m.reichl@fivetechno.de>
> > Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
> > ---
> > v3:
> > - replaced ad hoc checks by proper test for proper value of the
> >   compatible string in drivers/usb/core/of.c
> > v2:
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml
> > .org%2Flkml%2F2019%2F5%2F8%2F321&amp;data=02%7C01%7Cpeter.chen%
> 40nxp.c
> >
> om%7Cd9336abb14a745fb152508d6d4afdbb5%7C686ea1d3bc2b4c6fa92cd99c5c3
> 016
> >
> 35%7C0%7C0%7C636930249105615889&amp;sdata=CIC09rcvf%2FFp5y6oRQtJ
> Hk%2Bb
> > k7QjvJHECpK36LT8ocU%3D&amp;reserved=0
> > v1:
> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkml
> > .org%2Flkml%2F2019%2F5%2F7%2F715&amp;data=02%7C01%7Cpeter.chen%
> 40nxp.c
> >
> om%7Cd9336abb14a745fb152508d6d4afdbb5%7C686ea1d3bc2b4c6fa92cd99c5c3
> 016
> >
> 35%7C0%7C0%7C636930249105625893&amp;sdata=RbbKufAqSKRZpY726zWne
> 9cDhlK0
> > mlkBghhOmkqelY8%3D&amp;reserved=0
> > ---
> >  drivers/usb/core/hub.c |  3 +++
> >  drivers/usb/core/of.c  | 31 +++++++++++++++++++++++++++++++
> > include/linux/usb/of.h |  2 ++
> >  3 files changed, 36 insertions(+)
> >
> > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index
> > 2f94568ba385..6f2438522d09 100644
> > --- a/drivers/usb/core/hub.c
> > +++ b/drivers/usb/core/hub.c
> > @@ -22,6 +22,7 @@
> >  #include <linux/usb.h>
> >  #include <linux/usbdevice_fs.h>
> >  #include <linux/usb/hcd.h>
> > +#include <linux/usb/of.h>
> >  #include <linux/usb/otg.h>
> >  #include <linux/usb/quirks.h>
> >  #include <linux/workqueue.h>
> > @@ -5023,6 +5024,8 @@ static void hub_port_connect(struct usb_hub *hub, int
> port1, u16 portstatus,
> >  		if (status < 0)
> >  			goto loop;
> >
> > +		usb_of_validate_device_node(udev);
> > +
> >  		if (udev->quirks & USB_QUIRK_DELAY_INIT)
> >  			msleep(2000);
> >
> > diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c index
> > 651708d8c908..2b6f16753edc 100644
> > --- a/drivers/usb/core/of.c
> > +++ b/drivers/usb/core/of.c
> > @@ -30,6 +30,12 @@ struct device_node *usb_of_get_device_node(struct
> usb_device *hub, int port1)
> >  	for_each_child_of_node(hub->dev.of_node, node) {
> >  		if (of_property_read_u32(node, "reg", &reg))
> >  			continue;
> > +		/*
> > +		 * idVendor and idProduct are not yet known, so check only
> > +		 * a presence of the compatible property.
> > +		 */
> 
> This function could be called from anywhere, so that comment seems a bit
> misplaced.
> 
> > +		if (!of_find_property(node, "compatible", NULL))
> > +			continue;
> 
> What if there is a node with a "compatible" property for some entirely different
> purpose?  Since that won't be caught, why bother with this test at all?
> 
> >  		if (reg == port1)
> >  			return node;
> > @@ -39,6 +45,31 @@ struct device_node *usb_of_get_device_node(struct
> > usb_device *hub, int port1)  }
> > EXPORT_SYMBOL_GPL(usb_of_get_device_node);
> >
> > +/**
> > + * usb_of_validate_device_node() - validate dt node of the probed USB
> > +device
> > + * @udev: USB device
> > + *
> > + * Validate devicetree node for the USB device. Compatible string
> > +must match
> > + * device's idVendor and idProduct, otherwise the of_node will be put
> > +and set
> > + * to NULL.
> > + */
> > +void usb_of_validate_device_node(struct usb_device *udev) {
> > +	char compatible[13];
> > +
> > +	if (!udev->dev.of_node)
> > +		return;
> > +
> > +	snprintf(compatible, sizeof(compatible), "usb%x,%x",
> > +		 le16_to_cpu(udev->descriptor.idVendor),
> > +		 le16_to_cpu(udev->descriptor.idProduct));
> > +
> > +	if (of_device_is_compatible(udev->dev.of_node, compatible) == 0) {
> > +		of_node_put(udev->dev.of_node);
> > +		udev->dev.of_node = NULL;
> > +	}
> > +}
> > +
> >  /**
> >   * usb_of_has_combined_node() - determine whether a device has a combined
> node
> >   * @udev: USB device
> > diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h index
> > dba55ccb9b53..9969efda03ad 100644
> > --- a/include/linux/usb/of.h
> > +++ b/include/linux/usb/of.h
> > @@ -24,6 +24,7 @@ bool usb_of_has_combined_node(struct usb_device
> > *udev);  struct device_node *usb_of_get_interface_node(struct usb_device *udev,
> >  		u8 config, u8 ifnum);
> >  struct device *usb_of_get_companion_dev(struct device *dev);
> > +void usb_of_validate_device_node(struct usb_device *udev);
> >  #else
> >  static inline enum usb_dr_mode
> >  of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0) @@ -57,6
> > +58,7 @@ static inline struct device *usb_of_get_companion_dev(struct
> > device *dev)  {
> >  	return NULL;
> >  }
> > +static inline void usb_of_validate_device_node(struct usb_device
> > +*udev) { }
> >  #endif
> >
> >  #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)
> > --
> > 2.17.1
> >
> 
> --
> Måns Rullgård

  reply	other threads:[~2019-05-10  3:10 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20190507125630eucas1p1c5fd171a8dc2a6b8eb9dd317fe245f0c@eucas1p1.samsung.com>
2019-05-07 12:56 ` [PATCH] usb: core: verify devicetree nodes for disabled interfaces Marek Szyprowski
2019-05-07 13:24   ` Måns Rullgård
2019-05-08 10:14     ` Marek Szyprowski
     [not found]       ` <CGME20190508104442eucas1p2ebdffa348465f2c28177601014614853@eucas1p2.samsung.com>
2019-05-08 10:44         ` [PATCH v2] " Marek Szyprowski
2019-05-08 11:46           ` Måns Rullgård
2019-05-08 13:49             ` Marek Szyprowski
2019-05-08 15:27               ` Måns Rullgård
     [not found]                 ` <CGME20190509084827eucas1p294962744fe70745c50b69a5349b5de68@eucas1p2.samsung.com>
2019-05-09  8:47                   ` [PATCH v3] usb: core: verify devicetree nodes for USB devices Marek Szyprowski
2019-05-09 18:55                     ` Måns Rullgård
2019-05-10  3:10                       ` Peter Chen [this message]
2019-05-10  9:43                         ` Marek Szyprowski
2019-05-13  9:00                           ` Peter Chen
2019-05-13  9:07                             ` Marek Szyprowski
2019-05-13  9:23                               ` Peter Chen
2019-05-13 10:03                                 ` Marek Szyprowski
2019-05-13 10:06                                   ` Måns Rullgård
2019-05-17 11:15                                     ` Marek Szyprowski
2019-05-13 10:03                           ` Måns Rullgård
2019-05-17 11:18                             ` Marek Szyprowski
2019-05-09 19:04                     ` Tobias Jakobi

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=VI1PR04MB5327AD56CA772284DFE663D08B0C0@VI1PR04MB5327.eurprd04.prod.outlook.com \
    --to=peter.chen@nxp.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.reichl@fivetechno.de \
    --cc=m.szyprowski@samsung.com \
    --cc=mans@mansr.com \
    --subject='RE: [PATCH v3] usb: core: verify devicetree nodes for USB devices' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).