Skip to contentSkip to conversation

phy: Add devm_of_phy_optional_get() helper

PATCH Superseded Geert Uytterhoeven 10 participants 23 messages Jan 18, 2023 – Jan 23, 2023

Subsystems (13)
Networking Network drivers USB PCI +9 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover phy: Add devm_of_phy_optional_get() helper

Hi all,

While there exist several optional_get() PHY helper functions, there is no optional variant of devm_of_phy_get(), leading to several drivers implementing this theirselves, sometimes in buggy ways.

Hence this series introduces a devm_of_phy_optional_get() helper(), and converts existing users of devm_of_phy_get() where appropriate.

This series been compile-tested only, but the new helper itself has been tested with a new user I am about to submit.

Thanks for your comments!

Geert Uytterhoeven (7):
phy: Add devm_of_phy_optional_get() helper
net: fman: memac: Convert to devm_of_phy_optional_get()
net: lan966x: Convert to devm_of_phy_optional_get()
net: ethernet: ti: am65-cpsw: Convert to devm_of_phy_optional_get()
PCI: tegra: Convert to devm_of_phy_optional_get()
usb: host: ehci-exynos: Convert to devm_of_phy_optional_get()
usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

 .../net/ethernet/freescale/fman/fman_memac.c  |  8 +++---
 .../ethernet/microchip/lan966x/lan966x_main.c |  5 ++--
 drivers/net/ethernet/ti/am65-cpsw-nuss.c      |  6 ++---
 drivers/pci/controller/pci-tegra.c            |  5 +---
 drivers/phy/phy-core.c                        | 26 +++++++++++++++++++
 drivers/usb/host/ehci-exynos.c                | 24 +++++------------
 drivers/usb/host/ohci-exynos.c                | 24 +++++------------
 include/linux/phy/phy.h                       |  9 ++++++
 8 files changed, 59 insertions(+), 48 deletions(-)
Signature · 17 lines
2.34.1

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#1 lore raw

PATCH 1/7 phy: Add devm_of_phy_optional_get() helper

Add an optional variant of devm_of_phy_get(), so drivers no longer have to open-code this operation.

---
 drivers/phy/phy-core.c  | 26 ++++++++++++++++++++++++++
 include/linux/phy/phy.h |  9 ++++++++
 2 files changed, 35 insertions(+)
drivers/phy/phy-core.c +26 -0
index d93ddf1262c5178b..ea009a611e19c705 100644
@@ -879,6 +879,32 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(devm_of_phy_get);
 
+/**
+ * devm_of_phy_optional_get() - lookup and obtain a reference to an optional
+ * phy.
+ * @dev: device that requests this phy
+ * @np: node containing the phy
+ * @con_id: name of the phy from device's point of view
+ *
+ * Gets the phy using of_phy_get(), and associates a device with it using
+ * devres. On driver detach, release function is invoked on the devres data,
+ * then, devres data is freed.  This differs to devm_of_phy_get() in
+ * that if the phy does not exist, it is not considered an error and
+ * -ENODEV will not be returned. Instead the NULL phy is returned,
+ * which can be passed to all other phy consumer calls.
+ */
+struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np,
+				     const char *con_id)
+{
+	struct phy *phy = devm_of_phy_get(dev, np, con_id);
+
+	if (PTR_ERR(phy) == -ENODEV)
+		phy = NULL;
+
+	return phy;
+}
+EXPORT_SYMBOL_GPL(devm_of_phy_optional_get);
+
 /**
  * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index.
  * @dev: device that requests this phy
include/linux/phy/phy.h +9 -0
index 559c3da515073697..5f6e669b616da0b0 100644
@@ -255,6 +255,8 @@ struct phy *devm_phy_get(struct device *dev, const char *string);
 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
 			    const char *con_id);
+struct phy *devm_of_phy_optional_get(struct device *dev, struct device_node *np,
+				     const char *con_id);
 struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np,
 				     int index);
 void of_phy_put(struct phy *phy);
@@ -450,6 +452,13 @@ static inline struct phy *devm_of_phy_get(struct device *dev,
 	return ERR_PTR(-ENOSYS);
 }
 
+static inline struct phy *devm_of_phy_optional_get(struct device *dev,
+						   struct device_node *np,
+						   const char *con_id)
+{
+	return NULL;
+}
+
 static inline struct phy *devm_of_phy_get_by_index(struct device *dev,
 						   struct device_node *np,
 						   int index)
Signature · 7 lines
2.34.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer
#2 lore raw
Quoted 2 lines · On Wed, 18 Jan 2023 11:15:14 +0100 Geert Uytterhoeven wrote:

Add an optional variant of devm_of_phy_get(), so drivers no longer have to open-code this operation.

For merging could you put this one on an immutable branch and then everyone can pull + apply patches for callers from their section?

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer
#3 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Wed, 18 Jan 2023 11:15:14 +0100 Geert Uytterhoeven wrote:

Add an optional variant of devm_of_phy_get(), so drivers no longer have to open-code this operation.

For merging could you put this one on an immutable branch and then everyone can pull + apply patches for callers from their section?

Since this is phy, I can do that and everyone else can merge that in or all changes can go thru phy tree

Thanks

Signature · 6 lines
~Vinod

-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer
#4 lore raw
Quoted 5 lines · On Thu, 19 Jan 2023 16:44:35 +0530 Vinod Koul wrote:
Quoted 2 lines

For merging could you put this one on an immutable branch and then everyone can pull + apply patches for callers from their section?

Since this is phy, I can do that and everyone else can merge that in or all changes can go thru phy tree

Great! The microchip and ti drivers are relatively actively developed, I reckon it's worth going the branch way.

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

PATCH 2/7 net: fman: memac: Convert to devm_of_phy_optional_get()

In reply to Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

---
 drivers/net/ethernet/freescale/fman/fman_memac.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/freescale/fman/fman_memac.c +4 -4
index 9349f841bd0645a0..892277f13048660d 100644
@@ -1152,12 +1152,12 @@ int memac_initialization(struct mac_device *mac_dev,
 	else
 		memac->sgmii_pcs = pcs;
 
-	memac->serdes = devm_of_phy_get(mac_dev->dev, mac_node, "serdes");
-	err = PTR_ERR(memac->serdes);
-	if (err == -ENODEV || err == -ENOSYS) {
+	memac->serdes = devm_of_phy_optional_get(mac_dev->dev, mac_node,
+						 "serdes");
+	if (!memac->serdes) {
 		dev_dbg(mac_dev->dev, "could not get (optional) serdes\n");
-		memac->serdes = NULL;
 	} else if (IS_ERR(memac->serdes)) {
+		err = PTR_ERR(memac->serdes);
 		dev_err_probe(mac_dev->dev, err, "could not get serdes\n");
 		goto _return_fm_mac_free;
 	}
Signature · 7 lines
2.34.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
Reviewed-by on v1 2/7
#6 lore raw

Re: [PATCH 2/7] net: fman: memac: Convert to devm_of_phy_optional_get()

Quoted 19 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

---
 drivers/net/ethernet/freescale/fman/fman_memac.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/ethernet/freescale/fman/fman_memac.c +0 -3
index 9349f841bd0645a0..892277f13048660d 100644
@@ -1152,12 +1152,12 @@ int memac_initialization(struct mac_device *mac_dev,
 	else
 		memac->sgmii_pcs = pcs;
 
-	memac->serdes = devm_of_phy_get(mac_dev->dev, mac_node, "serdes");
-	err = PTR_ERR(memac->serdes);
-	if (err == -ENODEV || err == -ENOSYS) {

drivers/net/ethernet/freescale/fman/fman_memac.c int memac_initialization(struct mac_device *mac_dev, · line 1163

Quoted 10 lines
drivers/net/ethernet/freescale/fman/fman_memac.c +4 -1
+	memac->serdes = devm_of_phy_optional_get(mac_dev->dev, mac_node,
+						 "serdes");
+	if (!memac->serdes) {
 		dev_dbg(mac_dev->dev, "could not get (optional) serdes\n");
-		memac->serdes = NULL;
 	} else if (IS_ERR(memac->serdes)) {
+		err = PTR_ERR(memac->serdes);
 		dev_err_probe(mac_dev->dev, err, "could not get serdes\n");
 		goto _return_fm_mac_free;
 	}
#7 lore raw

PATCH 3/7 net: lan966x: Convert to devm_of_phy_optional_get()

In reply to Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

---
 drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_main.c +2 -3
index cadde20505ba0689..d64a525cdc9ea18b 100644
@@ -1147,9 +1147,8 @@ static int lan966x_probe(struct platform_device *pdev)
 		lan966x->ports[p]->config.portmode = phy_mode;
 		lan966x->ports[p]->fwnode = fwnode_handle_get(portnp);
 
-		serdes = devm_of_phy_get(lan966x->dev, to_of_node(portnp), NULL);
-		if (PTR_ERR(serdes) == -ENODEV)
-			serdes = NULL;
+		serdes = devm_of_phy_optional_get(lan966x->dev,
+						  to_of_node(portnp), NULL);
 		if (IS_ERR(serdes)) {
 			err = PTR_ERR(serdes);
 			goto cleanup_ports;
Signature · 7 lines
2.34.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
Reviewed-by on v1 3/7
#8 lore raw

Re: [PATCH 3/7] net: lan966x: Convert to devm_of_phy_optional_get()

Hi Geert,

This looks good to me.

BR
Steen

Quoted 32 lines · Geert Uytterhoeven

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

---
 drivers/net/ethernet/microchip/lan966x/lan966x_main.c | 5 ++---

 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_main.c +2 -3
index cadde20505ba0689..d64a525cdc9ea18b 100644
@@ -1147,9 +1147,8 @@ static int lan966x_probe(struct platform_device *pdev)
                 lan966x->ports[p]->config.portmode = phy_mode;
                 lan966x->ports[p]->fwnode = fwnode_handle_get(portnp);
 
-               serdes = devm_of_phy_get(lan966x->dev, to_of_node(portnp),
 NULL);
-               if (PTR_ERR(serdes) == -ENODEV)
-                       serdes = NULL;
+               serdes = devm_of_phy_optional_get(lan966x->dev,
+                                                 to_of_node(portnp), NULL);
                 if (IS_ERR(serdes)) {
                         err = PTR_ERR(serdes);

                        goto cleanup_ports;
--
2.34.1

#9 lore raw

PATCH 4/7 net: ethernet: ti: am65-cpsw: Convert to devm_of_phy_optional_get()

In reply to Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

While at it, fix handling of other error codes (e.g. -EPROBE_DEFER).

---
 drivers/net/ethernet/ti/am65-cpsw-nuss.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/ti/am65-cpsw-nuss.c +3 -3
index 5cac982841845369..794f228c8d632f7a 100644
@@ -1460,9 +1460,9 @@ static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *por
 	struct phy *phy;
 	int ret;
 
-	phy = devm_of_phy_get(dev, port_np, name);
-	if (PTR_ERR(phy) == -ENODEV)
-		return 0;
+	phy = devm_of_phy_optional_get(dev, port_np, name);
+	if (IS_ERR_OR_NULL(phy))
+		return PTR_ERR_OR_ZERO(phy);
 
 	/* Serdes PHY exists. Store it. */
 	port->slave.serdes_phy = phy;
Signature · 7 lines
2.34.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#10 lore raw

PATCH 5/7 PCI: tegra: Convert to devm_of_phy_optional_get()

In reply to Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

---
 drivers/pci/controller/pci-tegra.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/pci/controller/pci-tegra.c +1 -4
index 929f9363e94bec71..5b8907c663e516ad 100644
@@ -1330,12 +1330,9 @@ static struct phy *devm_of_phy_optional_get_index(struct device *dev,
 	if (!name)
 		return ERR_PTR(-ENOMEM);
 
-	phy = devm_of_phy_get(dev, np, name);
+	phy = devm_of_phy_optional_get(dev, np, name);
 	kfree(name);
 
-	if (PTR_ERR(phy) == -ENODEV)
-		phy = NULL;
-
 	return phy;
 }
 
Signature · 7 lines
2.34.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
Acked-by on v1 5/7
#11 lore raw

Re: [PATCH 5/7] PCI: tegra: Convert to devm_of_phy_optional_get()

Quoted 4 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

Thanks!

Let me know if you want me to apply; otherwise I'll assume you will merge along with the [1/7] patch.

Quoted 30 lines
---
 drivers/pci/controller/pci-tegra.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/pci/controller/pci-tegra.c +1 -4
index 929f9363e94bec71..5b8907c663e516ad 100644
@@ -1330,12 +1330,9 @@ static struct phy *devm_of_phy_optional_get_index(struct device *dev,
 	if (!name)
 		return ERR_PTR(-ENOMEM);
 
-	phy = devm_of_phy_get(dev, np, name);
+	phy = devm_of_phy_optional_get(dev, np, name);
 	kfree(name);
 
-	if (PTR_ERR(phy) == -ENODEV)
-		phy = NULL;
-
 	return phy;
 }
 
Signature · 7 lines
2.34.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#12 lore raw

PATCH 6/7 usb: host: ehci-exynos: Convert to devm_of_phy_optional_get()

In reply to Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

---
 drivers/usb/host/ehci-exynos.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/usb/host/ehci-exynos.c +7 -17
index a333231616f437b8..0f8d7df4937b2da4 100644
@@ -80,19 +80,12 @@ static int exynos_ehci_get_phy(struct device *dev,
 			return -EINVAL;
 		}
 
-		phy = devm_of_phy_get(dev, child, NULL);
+		phy = devm_of_phy_optional_get(dev, child, NULL);
 		exynos_ehci->phy[phy_number] = phy;
 		if (IS_ERR(phy)) {
-			ret = PTR_ERR(phy);
-			if (ret == -EPROBE_DEFER) {
-				of_node_put(child);
-				return ret;
-			} else if (ret != -ENOSYS && ret != -ENODEV) {
-				dev_err(dev,
-					"Error retrieving usb2 phy: %d\n", ret);
-				of_node_put(child);
-				return ret;
-			}
+			of_node_put(child);
+			return dev_err_probe(dev, PTR_ERR(phy),
+					     "Error retrieving usb2 phy\n");
 		}
 	}
 
@@ -108,12 +101,10 @@ static int exynos_ehci_phy_enable(struct device *dev)
 	int ret = 0;
 
 	for (i = 0; ret == 0 && i < PHY_NUMBER; i++)
-		if (!IS_ERR(exynos_ehci->phy[i]))
-			ret = phy_power_on(exynos_ehci->phy[i]);
+		ret = phy_power_on(exynos_ehci->phy[i]);
 	if (ret)
 		for (i--; i >= 0; i--)
-			if (!IS_ERR(exynos_ehci->phy[i]))
-				phy_power_off(exynos_ehci->phy[i]);
+			phy_power_off(exynos_ehci->phy[i]);
 
 	return ret;
 }
@@ -125,8 +116,7 @@ static void exynos_ehci_phy_disable(struct device *dev)
 	int i;
 
 	for (i = 0; i < PHY_NUMBER; i++)
-		if (!IS_ERR(exynos_ehci->phy[i]))
-			phy_power_off(exynos_ehci->phy[i]);
+		phy_power_off(exynos_ehci->phy[i]);
 }
 
 static void exynos_setup_vbus_gpio(struct device *dev)
Signature · 7 lines
2.34.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer Reviewed-by on v1 6/7
#13 lore raw

Re: [PATCH 6/7] usb: host: ehci-exynos: Convert to devm_of_phy_optional_get()

Quoted 11 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

---
 drivers/usb/host/ehci-exynos.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#14 lore raw

PATCH 7/7 usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

In reply to Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

---
 drivers/usb/host/ohci-exynos.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/usb/host/ohci-exynos.c +7 -17
index 8d7977fd5d3bd502..8dd9c3b2411c383f 100644
@@ -69,19 +69,12 @@ static int exynos_ohci_get_phy(struct device *dev,
 			return -EINVAL;
 		}
 
-		phy = devm_of_phy_get(dev, child, NULL);
+		phy = devm_of_phy_optional_get(dev, child, NULL);
 		exynos_ohci->phy[phy_number] = phy;
 		if (IS_ERR(phy)) {
-			ret = PTR_ERR(phy);
-			if (ret == -EPROBE_DEFER) {
-				of_node_put(child);
-				return ret;
-			} else if (ret != -ENOSYS && ret != -ENODEV) {
-				dev_err(dev,
-					"Error retrieving usb2 phy: %d\n", ret);
-				of_node_put(child);
-				return ret;
-			}
+			of_node_put(child);
+			return dev_err_probe(dev, PTR_ERR(phy),
+					     "Error retrieving usb2 phy\n");
 		}
 	}
 
@@ -97,12 +90,10 @@ static int exynos_ohci_phy_enable(struct device *dev)
 	int ret = 0;
 
 	for (i = 0; ret == 0 && i < PHY_NUMBER; i++)
-		if (!IS_ERR(exynos_ohci->phy[i]))
-			ret = phy_power_on(exynos_ohci->phy[i]);
+		ret = phy_power_on(exynos_ohci->phy[i]);
 	if (ret)
 		for (i--; i >= 0; i--)
-			if (!IS_ERR(exynos_ohci->phy[i]))
-				phy_power_off(exynos_ohci->phy[i]);
+			phy_power_off(exynos_ohci->phy[i]);
 
 	return ret;
 }
@@ -114,8 +105,7 @@ static void exynos_ohci_phy_disable(struct device *dev)
 	int i;
 
 	for (i = 0; i < PHY_NUMBER; i++)
-		if (!IS_ERR(exynos_ohci->phy[i]))
-			phy_power_off(exynos_ohci->phy[i]);
+		phy_power_off(exynos_ohci->phy[i]);
 }
 
 static int exynos_ohci_probe(struct platform_device *pdev)
Signature · 7 lines
2.34.1


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer
#15 lore raw

Re: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

Quoted 5 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

The patch ignores a possible -ENOSYS error return. Is it known that this will never happen?

Alan Stern

Quoted 61 lines
---
 drivers/usb/host/ohci-exynos.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/usb/host/ohci-exynos.c +7 -17
index 8d7977fd5d3bd502..8dd9c3b2411c383f 100644
@@ -69,19 +69,12 @@ static int exynos_ohci_get_phy(struct device *dev,
 			return -EINVAL;
 		}
 
-		phy = devm_of_phy_get(dev, child, NULL);
+		phy = devm_of_phy_optional_get(dev, child, NULL);
 		exynos_ohci->phy[phy_number] = phy;
 		if (IS_ERR(phy)) {
-			ret = PTR_ERR(phy);
-			if (ret == -EPROBE_DEFER) {
-				of_node_put(child);
-				return ret;
-			} else if (ret != -ENOSYS && ret != -ENODEV) {
-				dev_err(dev,
-					"Error retrieving usb2 phy: %d\n", ret);
-				of_node_put(child);
-				return ret;
-			}
+			of_node_put(child);
+			return dev_err_probe(dev, PTR_ERR(phy),
+					     "Error retrieving usb2 phy\n");
 		}
 	}
 
@@ -97,12 +90,10 @@ static int exynos_ohci_phy_enable(struct device *dev)
 	int ret = 0;
 
 	for (i = 0; ret == 0 && i < PHY_NUMBER; i++)
-		if (!IS_ERR(exynos_ohci->phy[i]))
-			ret = phy_power_on(exynos_ohci->phy[i]);
+		ret = phy_power_on(exynos_ohci->phy[i]);
 	if (ret)
 		for (i--; i >= 0; i--)
-			if (!IS_ERR(exynos_ohci->phy[i]))
-				phy_power_off(exynos_ohci->phy[i]);
+			phy_power_off(exynos_ohci->phy[i]);
 
 	return ret;
 }
@@ -114,8 +105,7 @@ static void exynos_ohci_phy_disable(struct device *dev)
 	int i;
 
 	for (i = 0; i < PHY_NUMBER; i++)
-		if (!IS_ERR(exynos_ohci->phy[i]))
-			phy_power_off(exynos_ohci->phy[i]);
+		phy_power_off(exynos_ohci->phy[i]);
 }
 
 static int exynos_ohci_probe(struct platform_device *pdev)
Signature · 1 line
2.34.1
Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#16 lore raw

Re: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

Hi Alan,

Quoted 9 lines · Alan Stern
Quoted 5 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

The patch ignores a possible -ENOSYS error return. Is it known that this will never happen?

While some phy_*() dummies in include/linux/phy/phy.h do return -ENOSYS if CONFIG_GENERIC_PHY is not enabled, devm_of_phy_optional_get() returns NULL in that case, so I think this cannot happen.

Quoted 18 lines
Quoted 18 lines
drivers/usb/host/ohci-exynos.c +1 -9
@@ -69,19 +69,12 @@ static int exynos_ohci_get_phy(struct device *dev,
                      return -EINVAL;
              }
 
-             phy = devm_of_phy_get(dev, child, NULL);
+             phy = devm_of_phy_optional_get(dev, child, NULL);
              exynos_ohci->phy[phy_number] = phy;
              if (IS_ERR(phy)) {
-                     ret = PTR_ERR(phy);
-                     if (ret == -EPROBE_DEFER) {
-                             of_node_put(child);
-                             return ret;
-                     } else if (ret != -ENOSYS && ret != -ENODEV) {
-                             dev_err(dev,
-                                     "Error retrieving usb2 phy: %d\n", ret);
-                             of_node_put(child);
Quoted 8 lines

drivers/usb/host/ohci-exynos.c static int exynos_ohci_get_phy(struct device *dev, · line 80

Quoted 8 lines
drivers/usb/host/ohci-exynos.c +3 -2
-                             return ret;
-                     }
+                     of_node_put(child);
+                     return dev_err_probe(dev, PTR_ERR(phy),
+                                          "Error retrieving usb2 phy\n");
              }
      }
 

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

maintainer Acked-by
#17 lore raw

Re: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

Quoted 10 lines · Geert Uytterhoeven

Hi Alan,

Quoted 7 lines · Alan Stern
Quoted 5 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

Quoted 6 lines
Quoted 2 lines

The patch ignores a possible -ENOSYS error return. Is it known that this will never happen?

While some phy_*() dummies in include/linux/phy/phy.h do return -ENOSYS if CONFIG_GENERIC_PHY is not enabled, devm_of_phy_optional_get() returns NULL in that case, so I think this cannot happen.

You could mention that in the patch description. Apart from this one issue:

Alan Stern

reviewer
#18 lore raw

Re: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

In reply to Geert Uytterhoeven
Quoted 27 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

---
 drivers/usb/host/ohci-exynos.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/usb/host/ohci-exynos.c +1 -4
index 8d7977fd5d3bd502..8dd9c3b2411c383f 100644
@@ -69,19 +69,12 @@ static int exynos_ohci_get_phy(struct device *dev,
                        return -EINVAL;
                }
 
-               phy = devm_of_phy_get(dev, child, NULL);
+               phy = devm_of_phy_optional_get(dev, child, NULL);
                exynos_ohci->phy[phy_number] = phy;
                if (IS_ERR(phy)) {
-                       ret = PTR_ERR(phy);
-                       if (ret == -EPROBE_DEFER) {
-                               of_node_put(child);

drivers/usb/host/ohci-exynos.c static int exynos_ohci_get_phy(struct device *dev, · line 77

Quoted 10 lines
drivers/usb/host/ohci-exynos.c +3 -7
-                               return ret;
-                       } else if (ret != -ENOSYS && ret != -ENODEV) {
-                               dev_err(dev,
-                                       "Error retrieving usb2 phy: %d\n", ret);
-                               of_node_put(child);
-                               return ret;
-                       }
+                       of_node_put(child);
+                       return dev_err_probe(dev, PTR_ERR(phy),
+                                            "Error retrieving usb2 phy\n");

Optional is really the only reason for the caller to decide whether to print an error message or not. If we have both flavors of 'get', then really the 'get' functions should print an error message.

Rob

#19 lore raw

Re: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

Hi Rob,

Quoted 34 lines · Rob Herring
Quoted 32 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

---
 drivers/usb/host/ohci-exynos.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/usb/host/ohci-exynos.c +1 -10
index 8d7977fd5d3bd502..8dd9c3b2411c383f 100644
@@ -69,19 +69,12 @@ static int exynos_ohci_get_phy(struct device *dev,
                        return -EINVAL;
                }
 
-               phy = devm_of_phy_get(dev, child, NULL);
+               phy = devm_of_phy_optional_get(dev, child, NULL);
                exynos_ohci->phy[phy_number] = phy;
                if (IS_ERR(phy)) {
-                       ret = PTR_ERR(phy);
-                       if (ret == -EPROBE_DEFER) {
-                               of_node_put(child);
-                               return ret;
-                       } else if (ret != -ENOSYS && ret != -ENODEV) {
-                               dev_err(dev,
-                                       "Error retrieving usb2 phy: %d\n", ret);
-                               of_node_put(child);
-                               return ret;
Quoted 8 lines

drivers/usb/host/ohci-exynos.c static int exynos_ohci_get_phy(struct device *dev, · line 77

Quoted 4 lines
drivers/usb/host/ohci-exynos.c +3 -1
-                       }
+                       of_node_put(child);
+                       return dev_err_probe(dev, PTR_ERR(phy),
+                                            "Error retrieving usb2 phy\n");

Optional is really the only reason for the caller to decide whether to print an error message or not. If we have both flavors of 'get', then really the 'get' functions should print an error message.

In case of a real error, both should print an error message, right?

Anyway, I understand that's a three step operation:
1. Introduce and convert to the _optional variant,
2. Add error printing to callees.
3. Remove error printing from callers.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

reviewer
#20 lore raw

Re: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

Quoted 47 lines · Geert Uytterhoeven

Hi Rob,

Quoted 34 lines · Rob Herring
Quoted 32 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

---
 drivers/usb/host/ohci-exynos.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/usb/host/ohci-exynos.c +1 -10
index 8d7977fd5d3bd502..8dd9c3b2411c383f 100644
@@ -69,19 +69,12 @@ static int exynos_ohci_get_phy(struct device *dev,
                        return -EINVAL;
                }
 
-               phy = devm_of_phy_get(dev, child, NULL);
+               phy = devm_of_phy_optional_get(dev, child, NULL);
                exynos_ohci->phy[phy_number] = phy;
                if (IS_ERR(phy)) {
-                       ret = PTR_ERR(phy);
-                       if (ret == -EPROBE_DEFER) {
-                               of_node_put(child);
-                               return ret;
-                       } else if (ret != -ENOSYS && ret != -ENODEV) {
-                               dev_err(dev,
-                                       "Error retrieving usb2 phy: %d\n", ret);
-                               of_node_put(child);
-                               return ret;
Quoted 8 lines

drivers/usb/host/ohci-exynos.c static int exynos_ohci_get_phy(struct device *dev, · line 77

Quoted 4 lines
drivers/usb/host/ohci-exynos.c +3 -1
-                       }
+                       of_node_put(child);
+                       return dev_err_probe(dev, PTR_ERR(phy),
+                                            "Error retrieving usb2 phy\n");

Optional is really the only reason for the caller to decide whether to print an error message or not. If we have both flavors of 'get', then really the 'get' functions should print an error message.

Quoted 6 lines

In case of a real error, both should print an error message, right?

Anyway, I understand that's a three step operation:
1. Introduce and convert to the _optional variant,
2. Add error printing to callees.
3. Remove error printing from callers.

I think you only need 2 out of 3 steps depending on the situation. In this case, you can add error printing in the _optional variant when you introduce it and then convert callers to it.

Where we already have an optional variant, then you need steps 2 and 3.

Rob

#21 lore raw

Re: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

Hi Rob,

Quoted 53 lines · Rob Herring
Quoted 44 lines · Geert Uytterhoeven
Quoted 34 lines · Rob Herring
Quoted 32 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

---
 drivers/usb/host/ohci-exynos.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/usb/host/ohci-exynos.c +1 -10
index 8d7977fd5d3bd502..8dd9c3b2411c383f 100644
@@ -69,19 +69,12 @@ static int exynos_ohci_get_phy(struct device *dev,
                        return -EINVAL;
                }
 
-               phy = devm_of_phy_get(dev, child, NULL);
+               phy = devm_of_phy_optional_get(dev, child, NULL);
                exynos_ohci->phy[phy_number] = phy;
                if (IS_ERR(phy)) {
-                       ret = PTR_ERR(phy);
-                       if (ret == -EPROBE_DEFER) {
-                               of_node_put(child);
-                               return ret;
-                       } else if (ret != -ENOSYS && ret != -ENODEV) {
-                               dev_err(dev,
-                                       "Error retrieving usb2 phy: %d\n", ret);
-                               of_node_put(child);
-                               return ret;
Quoted 8 lines

drivers/usb/host/ohci-exynos.c static int exynos_ohci_get_phy(struct device *dev, · line 77

Quoted 4 lines
drivers/usb/host/ohci-exynos.c +3 -1
-                       }
+                       of_node_put(child);
+                       return dev_err_probe(dev, PTR_ERR(phy),
+                                            "Error retrieving usb2 phy\n");

Optional is really the only reason for the caller to decide whether to print an error message or not. If we have both flavors of 'get', then really the 'get' functions should print an error message.

Quoted 6 lines

In case of a real error, both should print an error message, right?

Anyway, I understand that's a three step operation:
1. Introduce and convert to the _optional variant,
2. Add error printing to callees.
3. Remove error printing from callers.

Quoted 5 lines

I think you only need 2 out of 3 steps depending on the situation. In this case, you can add error printing in the _optional variant when you introduce it and then convert callers to it.

Where we already have an optional variant, then you need steps 2 and 3.

Right, so the error printing can be done now, while introducing devm_of_phy_optional_get().

Vinod: Do you agree?
If yes, I can respin with that change.
If not, I'll have to respin anyway, as the bug in am65_cpsw_init_serdes_phy() has been fixed in the meantime.

Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

maintainer
#22 lore raw

Re: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()

Quoted 60 lines · Geert Uytterhoeven

Hi Rob,

Quoted 57 lines · Rob Herring
Quoted 44 lines · Geert Uytterhoeven
Quoted 34 lines · Rob Herring
Quoted 32 lines · Geert Uytterhoeven

Use the new devm_of_phy_optional_get() helper instead of open-coding the same operation.

This lets us drop several checks for IS_ERR(), as phy_power_{on,off}() handle NULL parameters fine.

---
 drivers/usb/host/ohci-exynos.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/usb/host/ohci-exynos.c +1 -10
index 8d7977fd5d3bd502..8dd9c3b2411c383f 100644
@@ -69,19 +69,12 @@ static int exynos_ohci_get_phy(struct device *dev,
                        return -EINVAL;
                }
 
-               phy = devm_of_phy_get(dev, child, NULL);
+               phy = devm_of_phy_optional_get(dev, child, NULL);
                exynos_ohci->phy[phy_number] = phy;
                if (IS_ERR(phy)) {
-                       ret = PTR_ERR(phy);
-                       if (ret == -EPROBE_DEFER) {
-                               of_node_put(child);
-                               return ret;
-                       } else if (ret != -ENOSYS && ret != -ENODEV) {
-                               dev_err(dev,
-                                       "Error retrieving usb2 phy: %d\n", ret);
-                               of_node_put(child);
-                               return ret;
Quoted 8 lines

drivers/usb/host/ohci-exynos.c static int exynos_ohci_get_phy(struct device *dev, · line 77

Quoted 4 lines
drivers/usb/host/ohci-exynos.c +3 -1
-                       }
+                       of_node_put(child);
+                       return dev_err_probe(dev, PTR_ERR(phy),
+                                            "Error retrieving usb2 phy\n");

Optional is really the only reason for the caller to decide whether to print an error message or not. If we have both flavors of 'get', then really the 'get' functions should print an error message.

Quoted 6 lines

In case of a real error, both should print an error message, right?

Anyway, I understand that's a three step operation:
1. Introduce and convert to the _optional variant,
2. Add error printing to callees.
3. Remove error printing from callers.

I think you only need 2 out of 3 steps depending on the situation. In this case, you can add error printing in the _optional variant when you introduce it and then convert callers to it.

Quoted 6 lines
Quoted 1 line

Where we already have an optional variant, then you need steps 2 and 3.

Right, so the error printing can be done now, while introducing devm_of_phy_optional_get().

Vinod: Do you agree?

Ack.. IMO makes it better that way

Quoted 1 line

If yes, I can respin with that change.

ok

Quoted 20 lines

If not, I'll have to respin anyway, as the bug in am65_cpsw_init_serdes_phy() has been fixed in the meantime.

Thanks!

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

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

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