Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1190706yba; Thu, 9 May 2019 12:15:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqykOJ+O3wh9aA1XeLTq+ebsrVQb612quWqDTvd6pPffVXP4P/y303hmcmxxvD3fPTavjim7 X-Received: by 2002:a63:7887:: with SMTP id t129mr7816232pgc.339.1557429308871; Thu, 09 May 2019 12:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557429308; cv=none; d=google.com; s=arc-20160816; b=x2iG3fdQKSImXyf6wNAsSmQomLNfVj7m43I6jCSQ7b9ha5e5IDiVF9PRNzeAjNoqIV sZrmRVOAkhv3t9wnAldfp9eUkZk6z7r9LBSvWFXysdPx9dIUGrUC9JhJYN9BvUvr+/Tl oak7/u6NXnK5bgvs7grDo4Pqq5Yze/OVMt5tQ1YjM48WsOV+8GnorfVB1VrhsEqrN4BG SNHmgADVfYkk7DqdxSk2m3bF8O20YZjnCQ0+fdfVOUcqrliHK/LXiuUo7idhaqG+2keB pwPwlYpxWS6yCu4yUA7QzOzLbb4KSDZ2nnT6I4+jRawHgtT4tVw4ymoj/B0XwLrJCbxK Cfkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:autocrypt:openpgp:from :references:cc:to:subject; bh=k9daLjqptVoECd/eCLfVunvNXsYl2jt+fePR9eA/TMA=; b=s+HyiJwVXwwwDmOCL5GnHxbdTi19bjXzbv0O6rjhycgMmciVaW4Rl8pWqu2miOOc3n q8eZyfNZpFZGX9ts2ML7E8UGIbGPazsz4XxNoYNeIS8aRIyE3Zzo4vgzNLgMBaQG/YGz ArIfBCKk6xxTS6AGE5XnBUeM/BLCPPJHBH73sdXM+UDGWUjonaTaoKfrG5UEKwNgfosn 5XbLYfSKVZ6+0ct8Dp8M7xeEiUfatXzMZpLtUAQqjzdjdcJcUzWqgSXB9ajEC3W9KG1h ZuAw79cgbrHY1U4BfR1zf6+oZhGy0VRqGrHwBGr5+INrrJOoIxp7l6Z19tBQ0FzBbKU9 047w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1si4097010pfb.68.2019.05.09.12.14.52; Thu, 09 May 2019 12:15:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726928AbfEITNx (ORCPT + 99 others); Thu, 9 May 2019 15:13:53 -0400 Received: from smtp.math.uni-bielefeld.de ([129.70.45.10]:59793 "EHLO smtp.math.uni-bielefeld.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726749AbfEITNx (ORCPT ); Thu, 9 May 2019 15:13:53 -0400 X-Greylist: delayed 565 seconds by postgrey-1.27 at vger.kernel.org; Thu, 09 May 2019 15:13:51 EDT Received: from [192.168.0.100] (pC19F56B0.dip0.t-ipconnect.de [193.159.86.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by smtp.math.uni-bielefeld.de (Postfix) with ESMTPSA id E19545F595; Thu, 9 May 2019 21:04:23 +0200 (CEST) Subject: Re: [PATCH v3] usb: core: verify devicetree nodes for USB devices To: Marek Szyprowski , linux-usb@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Mans Rullgard , Bartlomiej Zolnierkiewicz , Markus Reichl , Krzysztof Kozlowski , Peter Chen References: <20190509084726.5405-1-m.szyprowski@samsung.com> From: Tobias Jakobi Openpgp: preference=signencrypt Autocrypt: addr=tjakobi@math.uni-bielefeld.de; prefer-encrypt=mutual; keydata= xsFNBFZhiNQBEAC5wiHN+jpZllNh3qv6Ni+32m4begD1A51ezJGHvubpy04S7noJ3BZvGeMf VBgp0ap0dtF3LHHKb5DRhakxU95jv3aIgVZCPztsZP7HLwwwdfI56PAy3r8IyvMxgokYZczM lPWcgYxV/cous+oLX/QjeTQ8GKkZqEfg0hK/CiBjenmBzc0BB2qlalMQP333113DIPYPbD97 3bA94/NBLlIf4HBMvvtS65s5UUtaAhnRBJ31pbrZnThwsQBktJp6UunOWGpvoPGJV5HYNPKg KKyuXkJbcN8rS3+AEz1BIlhirl+/F4MZKootDIE+oPmVtgY7wZWwHTatEgjy6D/DKgqUsfwW W/6jqYpOHRTw1iRh/vVvQ6/NCALwy0hlQWPSrA2HwjJSjwotv92mEG7+jQAjAbnFR9kaIaQa g4svIlP//hRb1ISloTl+/H5lnep2Jb3/fVS6sNEnaXVvPdcC1gUVddyMN7sJOgzn6IM6vx6l jq50hT3lIiTnKSqxOV7uNQdF85k43M208FT63GMKHJAmWsfPCOZJCY+tmkl5ezeN43iZ9W0q rsvaFpTtM4Aupjs826OIsx07PmCQFG5UtFVYK1ApoRzCp01zkW/UDN/Y1knC6SMvqY2O2u2J nhTG3+oTyvkpWtd4b1ozcUw7WNt2fY4xVXnt6yYvj+UcxEE2qwARAQABzWdUb2JpYXMgSmFr b2JpIChBbiBpbmZvcm1lZCBxdWVzdGlvbi4gQnV0IGRpZmZpY3VsdCB0byBhbnN3ZXIuIEkg YW0gd2hhdCB5b3Ugc2VlLikgPGxpcXVpZC5hY2lkQGdteC5uZXQ+wsGCBBMBAgAsAhsjBQkJ ZgGABwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AFAlZkjeMCGQEACgkQPuG7f7PKIigVTw// e3Y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, 9 May 2019 21:04:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.9.1 MIME-Version: 1.0 In-Reply-To: <20190509084726.5405-1-m.szyprowski@samsung.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Marek, I can confirm that this restores USB operation on my X2, so you can my Tested-by if you want. With best wishes, Tobias Marek Szyprowski wrote: > 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. > > Reported-by: Markus Reichl > Signed-off-by: Marek Szyprowski > --- > v3: > - replaced ad hoc checks by proper test for proper value of the > compatible string in drivers/usb/core/of.c > v2: https://lkml.org/lkml/2019/5/8/321 > v1: https://lkml.org/lkml/2019/5/7/715 > --- > 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 > #include > #include > +#include > #include > #include > #include > @@ -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", ®)) > continue; > + /* > + * idVendor and idProduct are not yet known, so check only > + * a presence of the compatible property. > + */ > + if (!of_find_property(node, "compatible", NULL)) > + continue; > > 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) >