Skip to contentSkip to conversation

usb: dwc3: drd: Avoid error when extcon is missing

PATCH In review Sam Protsenko 2 participants 3 messages Dec 11, 2020 – Dec 12, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: dwc3: drd: Avoid error when extcon is missing

If "port" node is missing in PHY controller node, dwc3_get_extcon() isn't able to find extcon device. This is perfectly fine in case when "usb-role-switch" or OTG is used, but next misleading error message is printed in that case, from of_graph_get_remote_node():

OF: graph: no port node found in /phy@1234abcd

Avoid printing that message by checking if port node exists in PHY node before calling of_graph_get_remote_node().

---
 drivers/usb/dwc3/drd.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
drivers/usb/dwc3/drd.c +16 -9
index 3e1c1aacf002..eaf389d3f3c5 100644
@@ -441,8 +441,8 @@ static int dwc3_drd_notifier(struct notifier_block *nb,
 static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 {
 	struct device *dev = dwc->dev;
-	struct device_node *np_phy, *np_conn;
-	struct extcon_dev *edev;
+	struct device_node *np_phy;
+	struct extcon_dev *edev = NULL;
 	const char *name;
 
 	if (device_property_read_bool(dev, "extcon"))
@@ -462,15 +462,22 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 		return edev;
 	}
 
+	/*
+	 * Try to get extcon device from USB PHY controller's "port" node.
+	 * Check if it has the "port" node first, to avoid printing the error
+	 * message from underlying code, as it's a valid case: extcon device
+	 * (and "port" node) may be missing in case of "usb-role-switch" or OTG
+	 * mode.
+	 */
 	np_phy = of_parse_phandle(dev->of_node, "phys", 0);
-	np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+	if (of_graph_is_present(np_phy)) {
+		struct device_node *np_conn;
 
-	if (np_conn)
-		edev = extcon_find_edev_by_node(np_conn);
-	else
-		edev = NULL;
-
-	of_node_put(np_conn);
+		np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+		if (np_conn)
+			edev = extcon_find_edev_by_node(np_conn);
+		of_node_put(np_conn);
+	}
 	of_node_put(np_phy);
 
 	return edev;
Signature · 1 line
2.29.2
#1 lore raw
Quoted 9 lines · Sam Protsenko

If "port" node is missing in PHY controller node, dwc3_get_extcon() isn't able to find extcon device. This is perfectly fine in case when "usb-role-switch" or OTG is used, but next misleading error message is printed in that case, from of_graph_get_remote_node():

OF: graph: no port node found in /phy@1234abcd

Avoid printing that message by checking if port node exists in PHY node before calling of_graph_get_remote_node().

So, this has to be v2...
Anyway, see below.

...

Quoted 30 lines

static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) {

drivers/usb/dwc3/drd.c +11 -7
 	struct device *dev = dwc->dev;
-	struct device_node *np_phy, *np_conn;
-	struct extcon_dev *edev;
+	struct device_node *np_phy;
+	struct extcon_dev *edev = NULL;
 	const char *name;
 
 	if (device_property_read_bool(dev, "extcon"))
@@ -462,15 +462,22 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 		return edev;
 	}
 
+	/*
+	 * Try to get extcon device from USB PHY controller's "port" node.
+	 * Check if it has the "port" node first, to avoid printing the error
+	 * message from underlying code, as it's a valid case: extcon device
+	 * (and "port" node) may be missing in case of "usb-role-switch" or OTG
+	 * mode.
+	 */
 	np_phy = of_parse_phandle(dev->of_node, "phys", 0);
-	np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+	if (of_graph_is_present(np_phy)) {
+		struct device_node *np_conn;
 
-	if (np_conn)
-		edev = extcon_find_edev_by_node(np_conn);
-	else
-		edev = NULL;

drivers/usb/dwc3/drd.c static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) · line 483

Quoted 10 lines
drivers/usb/dwc3/drd.c +5 -2
-
-	of_node_put(np_conn);
+		np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+		if (np_conn)
+			edev = extcon_find_edev_by_node(np_conn);
+		of_node_put(np_conn);
+	}
 	of_node_put(np_phy);
 
 	return edev;

Why not do it slightly different, i.e.

- np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+ if (of_graph_is_present(np_phy))
+ np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+ else
+ np_conn = NULL;

?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 67 lines · Andy Shevchenko
Quoted 9 lines · Sam Protsenko

If "port" node is missing in PHY controller node, dwc3_get_extcon() isn't able to find extcon device. This is perfectly fine in case when "usb-role-switch" or OTG is used, but next misleading error message is printed in that case, from of_graph_get_remote_node():

OF: graph: no port node found in /phy@1234abcd

Avoid printing that message by checking if port node exists in PHY node before calling of_graph_get_remote_node().

So, this has to be v2...
Anyway, see below.

...

Quoted 30 lines

static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)

 {
      struct device *dev = dwc->dev;
drivers/usb/dwc3/drd.c +11 -7
-     struct device_node *np_phy, *np_conn;
-     struct extcon_dev *edev;
+     struct device_node *np_phy;
+     struct extcon_dev *edev = NULL;
      const char *name;
 
      if (device_property_read_bool(dev, "extcon"))
@@ -462,15 +462,22 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
              return edev;
      }
 
+     /*
+      * Try to get extcon device from USB PHY controller's "port" node.
+      * Check if it has the "port" node first, to avoid printing the error
+      * message from underlying code, as it's a valid case: extcon device
+      * (and "port" node) may be missing in case of "usb-role-switch" or OTG
+      * mode.
+      */
      np_phy = of_parse_phandle(dev->of_node, "phys", 0);
-     np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+     if (of_graph_is_present(np_phy)) {
+             struct device_node *np_conn;
 
-     if (np_conn)
-             edev = extcon_find_edev_by_node(np_conn);
-     else
-             edev = NULL;

drivers/usb/dwc3/drd.c static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc) · line 483

Quoted 10 lines
drivers/usb/dwc3/drd.c +5 -2
-
-     of_node_put(np_conn);
+             np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+             if (np_conn)
+                     edev = extcon_find_edev_by_node(np_conn);
+             of_node_put(np_conn);
+     }
      of_node_put(np_phy);
 
      return edev;

Why not do it slightly different, i.e.

(quoted diff) +4 -1
-       np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+       if (of_graph_is_present(np_phy))
+               np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+       else
+               np_conn = NULL;
Quoted 2 lines

?

Thanks for the review, Andy! I'll address this in v3.

Quoted 5 lines

--
With Best Regards,
Andy Shevchenko