Skip to contentSkip to conversation

phy: rockchip-inno-usb2: Return zero after otg sync

PATCH Superseded Peter Geis 2 participants 3 messages Aug 24, 2022 – Sep 2, 2022

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Peter Geis

author
#0 lore raw

PATCH v3 1/1 phy: rockchip-inno-usb2: Return zero after otg sync

The otg sync state patch reuses the ret variable, but fails to set it to zero after use. This leads to a situation when the otg port is in peripheral mode where the otg phy aborts halfway through setup. It also fails to account for a failure to register the extcon notifier. Fix this by using our own variable and skipping otg sync in case of failure.

Fixes 8dc60f8da22f ("phy: rockchip-inno-usb2: Sync initial otg state")

---
Changelog:
v3
- add missing brackets around new goto
v2
- switch to using our own variable
- add missing goto to skip sync in case of registration failure

---
 drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +6 -3
index 0b1e9337ee8e..27da5ba379c4 100644
@@ -1124,7 +1124,7 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
 					  struct rockchip_usb2phy_port *rport,
 					  struct device_node *child_np)
 {
-	int ret;
+	int ret, id;
 
 	rport->port_id = USB2PHY_PORT_OTG;
 	rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_OTG];
@@ -1163,12 +1163,15 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
 		ret = devm_extcon_register_notifier(rphy->dev, rphy->edev,
 					EXTCON_USB_HOST, &rport->event_nb);
 		if (ret)
+		{
 			dev_err(rphy->dev, "register USB HOST notifier failed\n");
+			goto out;
+		}
 
 		if (!of_property_read_bool(rphy->dev->of_node, "extcon")) {
 			/* do initial sync of usb state */
-			ret = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
-			extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !ret);
+			id = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
+			extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !id);
 		}
 	}
 
Signature · 7 lines
2.25.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer
#1 lore raw
Quoted 8 lines · Peter Geis

The otg sync state patch reuses the ret variable, but fails to set it to zero after use. This leads to a situation when the otg port is in peripheral mode where the otg phy aborts halfway through setup. It also fails to account for a failure to register the extcon notifier. Fix this by using our own variable and skipping otg sync in case of failure.

Fixes 8dc60f8da22f ("phy: rockchip-inno-usb2: Sync initial otg state")

No blank here please

Quoted 30 lines

---
Changelog:
v3
- add missing brackets around new goto
v2
- switch to using our own variable
- add missing goto to skip sync in case of registration failure

---
 drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +1 -1
index 0b1e9337ee8e..27da5ba379c4 100644
@@ -1124,7 +1124,7 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
 					  struct rockchip_usb2phy_port *rport,
 					  struct device_node *child_np)
 {
-	int ret;
+	int ret, id;
 
 	rport->port_id = USB2PHY_PORT_OTG;
 	rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_OTG];

drivers/phy/rockchip/phy-rockchip-inno-usb2.c static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, · line 1166

Quoted 4 lines
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +1 -0
@@ -1163,12 +1163,15 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
 		ret = devm_extcon_register_notifier(rphy->dev, rphy->edev,
 					EXTCON_USB_HOST, &rport->event_nb);
 		if (ret)
+		{

:-(

this is _not_ linux kernel code style!

Reminder: it always helps to run checkpatch

Quoted 15 lines
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +4 -2
 			dev_err(rphy->dev, "register USB HOST notifier failed\n");
+			goto out;
+		}
 
 		if (!of_property_read_bool(rphy->dev->of_node, "extcon")) {
 			/* do initial sync of usb state */
-			ret = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
-			extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !ret);
+			id = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
+			extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !id);
 		}
 	}
 
Signature · 1 line
2.25.1
Signature · 1 line
~Vinod
author
#2 lore raw
Quoted 50 lines · Vinod Koul
Quoted 8 lines · Peter Geis

The otg sync state patch reuses the ret variable, but fails to set it to zero after use. This leads to a situation when the otg port is in peripheral mode where the otg phy aborts halfway through setup. It also fails to account for a failure to register the extcon notifier. Fix this by using our own variable and skipping otg sync in case of failure.

Fixes 8dc60f8da22f ("phy: rockchip-inno-usb2: Sync initial otg state")

No blank here please

Quoted 30 lines

---
Changelog:
v3
- add missing brackets around new goto
v2
- switch to using our own variable
- add missing goto to skip sync in case of registration failure

---
 drivers/phy/rockchip/phy-rockchip-inno-usb2.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +1 -1
index 0b1e9337ee8e..27da5ba379c4 100644
@@ -1124,7 +1124,7 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
                                        struct rockchip_usb2phy_port *rport,
                                        struct device_node *child_np)
 {
-     int ret;
+     int ret, id;
 
      rport->port_id = USB2PHY_PORT_OTG;
      rport->port_cfg = &rphy->phy_cfg->port_cfgs[USB2PHY_PORT_OTG];

drivers/phy/rockchip/phy-rockchip-inno-usb2.c static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy, · line 1166

Quoted 4 lines
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +1 -0
@@ -1163,12 +1163,15 @@ static int rockchip_usb2phy_otg_port_init(struct rockchip_usb2phy *rphy,
              ret = devm_extcon_register_notifier(rphy->dev, rphy->edev,
                                      EXTCON_USB_HOST, &rport->event_nb);
              if (ret)
+             {

:-(

Quoted 3 lines

this is _not_ linux kernel code style!

Reminder: it always helps to run checkpatch

Ouch, yeah that's really embarrassing. Thank you for catching it.

Quoted 19 lines
Quoted 15 lines
drivers/phy/rockchip/phy-rockchip-inno-usb2.c +4 -3
                      dev_err(rphy->dev, "register USB HOST notifier failed\n");
+                     goto out;
+             }
 
              if (!of_property_read_bool(rphy->dev->of_node, "extcon")) {
                      /* do initial sync of usb state */
-                     ret = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
-                     extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !ret);
+                     id = property_enabled(rphy->grf, &rport->port_cfg->utmi_id);
+                     extcon_set_state_sync(rphy->edev, EXTCON_USB_HOST, !id);
              }
      }
 
--
Quoted 1 line

2.25.1

--
~Vinod

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy