phy: Add devm_of_phy_optional_get() helper
Subsystems (13)
PATCH 2/7 net: fman: memac: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse 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
@@ -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
PATCH 3/7 net: lan966x: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse 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
@@ -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
PATCH 6/7 usb: host: ehci-exynos: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse 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
@@ -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
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-phyPATCH 5/7 PCI: tegra: Convert to devm_of_phy_optional_get()
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
@@ -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
PATCH 7/7 usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse 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
@@ -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
PATCH 1/7 phy: Add devm_of_phy_optional_get() helper
In reply to Geert UytterhoevenAdd 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
@@ -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
@@ -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
PATCH 4/7 net: ethernet: ti: am65-cpsw: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenUse 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
@@ -1460,9 +1460,9 @@ static int am65_cpsw_init_serdes_phy(struct device *dev, struct device_node *porstruct 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
Alan Stern
maintainerRe: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenQuoted 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
Signed-off-by Geert Uytterhoeven <[email protected]>--- drivers/usb/host/ohci-exynos.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)drivers/usb/host/ohci-exynos.c +7
-17@@ -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
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
-ENOSYSerror 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
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
-ENOSYSerror return. Is it known that this will never happen?While some phy_*() dummies in
include/linux/phy/phy.hdo return-ENOSYSifCONFIG_GENERIC_PHYis 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
Rob Herring
reviewerRe: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenQuoted 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.Signed-off-by Geert Uytterhoeven <[email protected]>--- drivers/usb/host/ohci-exynos.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)drivers/usb/host/ohci-exynos.c +1
-4@@ -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
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.Signed-off-by Geert Uytterhoeven <[email protected]>--- drivers/usb/host/ohci-exynos.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)drivers/usb/host/ohci-exynos.c +1
-10@@ -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
Rob Herring
reviewerRe: [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.Signed-off-by Geert Uytterhoeven <[email protected]>--- drivers/usb/host/ohci-exynos.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)drivers/usb/host/ohci-exynos.c +1
-10@@ -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_optionalvariant,
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
Jakub Kicinski
maintainerQuoted 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
Vinod Koul
maintainerQuoted 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
Re: [PATCH 6/7] usb: host: ehci-exynos: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenQuoted 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.Signed-off-by Geert Uytterhoeven <[email protected]>--- 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
Jakub Kicinski
maintainerQuoted 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
Re: [PATCH 2/7] net: fman: memac: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenQuoted 19 lines · Geert Uytterhoeven
Use the new
devm_of_phy_optional_get()helper instead of open-coding the same operation.Signed-off-by Geert Uytterhoeven <[email protected]>--- 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@@ -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; }
Re: [PATCH 7/7] usb: host: ohci-exynos: Convert to devm_of_phy_optional_get()
In reply to Rob HerringHi 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.Signed-off-by Geert Uytterhoeven <[email protected]>--- drivers/usb/host/ohci-exynos.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)drivers/usb/host/ohci-exynos.c +1
-10@@ -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_optionalvariant,
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
_optionalvariant 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
Vinod Koul
maintainerRe: [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.Signed-off-by Geert Uytterhoeven <[email protected]>--- drivers/usb/host/ohci-exynos.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-)drivers/usb/host/ohci-exynos.c +1
-10@@ -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_optionalvariant,
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
_optionalvariant 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 TorvaldsSignature · 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
Re: [PATCH 3/7] net: lan966x: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenHi 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.Signed-off-by Geert Uytterhoeven <[email protected]>---
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@@ -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
Re: [PATCH 5/7] PCI: tegra: Convert to devm_of_phy_optional_get()
In reply to Geert UytterhoevenQuoted 4 lines · Geert Uytterhoeven
Use the new
devm_of_phy_optional_get()helper instead of open-coding the same operation.Signed-off-by Geert Uytterhoeven <[email protected]>
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@@ -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