* [PATCH 01/11] phy: broadcom: bcm-cygnus-pcie: Simplify with scoped for each OF child loop
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-29 16:04 ` Florian Fainelli
2024-08-26 10:07 ` [PATCH 02/11] phy: broadcom: brcm-sata: " Krzysztof Kozlowski
` (10 subsequent siblings)
11 siblings, 1 reply; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/broadcom/phy-bcm-cygnus-pcie.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/drivers/phy/broadcom/phy-bcm-cygnus-pcie.c b/drivers/phy/broadcom/phy-bcm-cygnus-pcie.c
index cc29b08e49eb..462c61a24ec5 100644
--- a/drivers/phy/broadcom/phy-bcm-cygnus-pcie.c
+++ b/drivers/phy/broadcom/phy-bcm-cygnus-pcie.c
@@ -113,11 +113,10 @@ static const struct phy_ops cygnus_pcie_phy_ops = {
static int cygnus_pcie_phy_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
- struct device_node *node = dev->of_node, *child;
+ struct device_node *node = dev->of_node;
struct cygnus_pcie_phy_core *core;
struct phy_provider *provider;
unsigned cnt = 0;
- int ret;
if (of_get_child_count(node) == 0) {
dev_err(dev, "PHY no child node\n");
@@ -136,35 +135,31 @@ static int cygnus_pcie_phy_probe(struct platform_device *pdev)
mutex_init(&core->lock);
- for_each_available_child_of_node(node, child) {
+ for_each_available_child_of_node_scoped(node, child) {
unsigned int id;
struct cygnus_pcie_phy *p;
if (of_property_read_u32(child, "reg", &id)) {
dev_err(dev, "missing reg property for %pOFn\n",
child);
- ret = -EINVAL;
- goto put_child;
+ return -EINVAL;
}
if (id >= MAX_NUM_PHYS) {
dev_err(dev, "invalid PHY id: %u\n", id);
- ret = -EINVAL;
- goto put_child;
+ return -EINVAL;
}
if (core->phys[id].phy) {
dev_err(dev, "duplicated PHY id: %u\n", id);
- ret = -EINVAL;
- goto put_child;
+ return -EINVAL;
}
p = &core->phys[id];
p->phy = devm_phy_create(dev, child, &cygnus_pcie_phy_ops);
if (IS_ERR(p->phy)) {
dev_err(dev, "failed to create PHY\n");
- ret = PTR_ERR(p->phy);
- goto put_child;
+ return PTR_ERR(p->phy);
}
p->core = core;
@@ -184,9 +179,6 @@ static int cygnus_pcie_phy_probe(struct platform_device *pdev)
dev_dbg(dev, "registered %u PCIe PHY(s)\n", cnt);
return 0;
-put_child:
- of_node_put(child);
- return ret;
}
static const struct of_device_id cygnus_pcie_phy_match_table[] = {
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH 01/11] phy: broadcom: bcm-cygnus-pcie: Simplify with scoped for each OF child loop
2024-08-26 10:07 ` [PATCH 01/11] phy: broadcom: bcm-cygnus-pcie: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-29 16:04 ` Florian Fainelli
0 siblings, 0 replies; 16+ messages in thread
From: Florian Fainelli @ 2024-08-29 16:04 UTC (permalink / raw)
To: Krzysztof Kozlowski, Vinod Koul, Kishon Vijay Abraham I, Ray Jui,
Scott Branden, Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm
On 8/26/24 03:07, Krzysztof Kozlowski wrote:
> Use scoped for_each_available_child_of_node_scoped() when iterating over
> device nodes to make code a bit simpler.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 02/11] phy: broadcom: brcm-sata: Simplify with scoped for each OF child loop
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 01/11] phy: broadcom: bcm-cygnus-pcie: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-29 16:04 ` Florian Fainelli
2024-08-26 10:07 ` [PATCH 03/11] phy: cadence: sierra: " Krzysztof Kozlowski
` (9 subsequent siblings)
11 siblings, 1 reply; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/broadcom/phy-brcm-sata.c | 21 +++++++--------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/drivers/phy/broadcom/phy-brcm-sata.c b/drivers/phy/broadcom/phy-brcm-sata.c
index ed9e18791ec9..228100357054 100644
--- a/drivers/phy/broadcom/phy-brcm-sata.c
+++ b/drivers/phy/broadcom/phy-brcm-sata.c
@@ -751,11 +751,11 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
{
const char *rxaeq_mode;
struct device *dev = &pdev->dev;
- struct device_node *dn = dev->of_node, *child;
+ struct device_node *dn = dev->of_node;
const struct of_device_id *of_id;
struct brcm_sata_phy *priv;
struct phy_provider *provider;
- int ret, count = 0;
+ int count = 0;
if (of_get_child_count(dn) == 0)
return -ENODEV;
@@ -782,26 +782,23 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
return PTR_ERR(priv->ctrl_base);
}
- for_each_available_child_of_node(dn, child) {
+ for_each_available_child_of_node_scoped(dn, child) {
unsigned int id;
struct brcm_sata_port *port;
if (of_property_read_u32(child, "reg", &id)) {
dev_err(dev, "missing reg property in node %pOFn\n",
child);
- ret = -EINVAL;
- goto put_child;
+ return -EINVAL;
}
if (id >= MAX_PORTS) {
dev_err(dev, "invalid reg: %u\n", id);
- ret = -EINVAL;
- goto put_child;
+ return -EINVAL;
}
if (priv->phys[id].phy) {
dev_err(dev, "already registered port %u\n", id);
- ret = -EINVAL;
- goto put_child;
+ return -EINVAL;
}
port = &priv->phys[id];
@@ -822,8 +819,7 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
port->ssc_en = of_property_read_bool(child, "brcm,enable-ssc");
if (IS_ERR(port->phy)) {
dev_err(dev, "failed to create PHY\n");
- ret = PTR_ERR(port->phy);
- goto put_child;
+ return PTR_ERR(port->phy);
}
phy_set_drvdata(port->phy, port);
@@ -839,9 +835,6 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
dev_info(dev, "registered %d port(s)\n", count);
return 0;
-put_child:
- of_node_put(child);
- return ret;
}
static struct platform_driver brcm_sata_phy_driver = {
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH 02/11] phy: broadcom: brcm-sata: Simplify with scoped for each OF child loop
2024-08-26 10:07 ` [PATCH 02/11] phy: broadcom: brcm-sata: " Krzysztof Kozlowski
@ 2024-08-29 16:04 ` Florian Fainelli
0 siblings, 0 replies; 16+ messages in thread
From: Florian Fainelli @ 2024-08-29 16:04 UTC (permalink / raw)
To: Krzysztof Kozlowski, Vinod Koul, Kishon Vijay Abraham I, Ray Jui,
Scott Branden, Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm
On 8/26/24 03:07, Krzysztof Kozlowski wrote:
> Use scoped for_each_available_child_of_node_scoped() when iterating over
> device nodes to make code a bit simpler.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
--
Florian
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 03/11] phy: cadence: sierra: Simplify with scoped for each OF child loop
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 01/11] phy: broadcom: bcm-cygnus-pcie: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 02/11] phy: broadcom: brcm-sata: " Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 04/11] phy: hisilicon: usb2: " Krzysztof Kozlowski
` (8 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/cadence/phy-cadence-sierra.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/phy/cadence/phy-cadence-sierra.c b/drivers/phy/cadence/phy-cadence-sierra.c
index 3010c9f24136..aeec6eb6be23 100644
--- a/drivers/phy/cadence/phy-cadence-sierra.c
+++ b/drivers/phy/cadence/phy-cadence-sierra.c
@@ -1366,7 +1366,7 @@ static int cdns_sierra_phy_probe(struct platform_device *pdev)
unsigned int id_value;
int ret, node = 0;
void __iomem *base;
- struct device_node *dn = dev->of_node, *child;
+ struct device_node *dn = dev->of_node;
if (of_get_child_count(dn) == 0)
return -ENODEV;
@@ -1438,7 +1438,7 @@ static int cdns_sierra_phy_probe(struct platform_device *pdev)
sp->autoconf = of_property_read_bool(dn, "cdns,autoconf");
- for_each_available_child_of_node(dn, child) {
+ for_each_available_child_of_node_scoped(dn, child) {
struct phy *gphy;
if (!(of_node_name_eq(child, "phy") ||
@@ -1452,7 +1452,6 @@ static int cdns_sierra_phy_probe(struct platform_device *pdev)
dev_err(dev, "failed to get reset %s\n",
child->full_name);
ret = PTR_ERR(sp->phys[node].lnk_rst);
- of_node_put(child);
goto put_control;
}
@@ -1461,7 +1460,6 @@ static int cdns_sierra_phy_probe(struct platform_device *pdev)
if (ret) {
dev_err(dev, "missing property in node %s\n",
child->name);
- of_node_put(child);
reset_control_put(sp->phys[node].lnk_rst);
goto put_control;
}
@@ -1475,7 +1473,6 @@ static int cdns_sierra_phy_probe(struct platform_device *pdev)
gphy = devm_phy_create(dev, child, &noop_ops);
if (IS_ERR(gphy)) {
ret = PTR_ERR(gphy);
- of_node_put(child);
reset_control_put(sp->phys[node].lnk_rst);
goto put_control;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH 04/11] phy: hisilicon: usb2: Simplify with scoped for each OF child loop
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
` (2 preceding siblings ...)
2024-08-26 10:07 ` [PATCH 03/11] phy: cadence: sierra: " Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 05/11] phy: mediatek: tphy: " Krzysztof Kozlowski
` (7 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/hisilicon/phy-hisi-inno-usb2.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/phy/hisilicon/phy-hisi-inno-usb2.c b/drivers/phy/hisilicon/phy-hisi-inno-usb2.c
index c138cd4807d6..c843923252aa 100644
--- a/drivers/phy/hisilicon/phy-hisi-inno-usb2.c
+++ b/drivers/phy/hisilicon/phy-hisi-inno-usb2.c
@@ -138,7 +138,6 @@ static int hisi_inno_phy_probe(struct platform_device *pdev)
struct device_node *np = dev->of_node;
struct hisi_inno_phy_priv *priv;
struct phy_provider *provider;
- struct device_node *child;
int i = 0;
int ret;
@@ -162,24 +161,20 @@ static int hisi_inno_phy_probe(struct platform_device *pdev)
priv->type = (uintptr_t) of_device_get_match_data(dev);
- for_each_child_of_node(np, child) {
+ for_each_child_of_node_scoped(np, child) {
struct reset_control *rst;
struct phy *phy;
rst = of_reset_control_get_exclusive(child, NULL);
- if (IS_ERR(rst)) {
- of_node_put(child);
+ if (IS_ERR(rst))
return PTR_ERR(rst);
- }
priv->ports[i].utmi_rst = rst;
priv->ports[i].priv = priv;
phy = devm_phy_create(dev, child, &hisi_inno_phy_ops);
- if (IS_ERR(phy)) {
- of_node_put(child);
+ if (IS_ERR(phy))
return PTR_ERR(phy);
- }
phy_set_bus_width(phy, 8);
phy_set_drvdata(phy, &priv->ports[i]);
@@ -187,7 +182,6 @@ static int hisi_inno_phy_probe(struct platform_device *pdev)
if (i >= INNO_PHY_PORT_NUM) {
dev_warn(dev, "Support %d ports in maximum\n", i);
- of_node_put(child);
break;
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH 05/11] phy: mediatek: tphy: Simplify with scoped for each OF child loop
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
` (3 preceding siblings ...)
2024-08-26 10:07 ` [PATCH 04/11] phy: hisilicon: usb2: " Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 06/11] phy: mediatek: xsphy: " Krzysztof Kozlowski
` (6 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/mediatek/phy-mtk-tphy.c | 30 +++++++++++-------------------
1 file changed, 11 insertions(+), 19 deletions(-)
diff --git a/drivers/phy/mediatek/phy-mtk-tphy.c b/drivers/phy/mediatek/phy-mtk-tphy.c
index 25b86bbb9cec..3f7095ec5978 100644
--- a/drivers/phy/mediatek/phy-mtk-tphy.c
+++ b/drivers/phy/mediatek/phy-mtk-tphy.c
@@ -1577,12 +1577,11 @@ static int mtk_tphy_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
- struct device_node *child_np;
struct phy_provider *provider;
struct resource *sif_res;
struct mtk_tphy *tphy;
struct resource res;
- int port, retval;
+ int port;
tphy = devm_kzalloc(dev, sizeof(*tphy), GFP_KERNEL);
if (!tphy)
@@ -1623,25 +1622,23 @@ static int mtk_tphy_probe(struct platform_device *pdev)
}
port = 0;
- for_each_child_of_node(np, child_np) {
+ for_each_child_of_node_scoped(np, child_np) {
struct mtk_phy_instance *instance;
struct clk_bulk_data *clks;
struct device *subdev;
struct phy *phy;
+ int retval;
instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL);
- if (!instance) {
- retval = -ENOMEM;
- goto put_child;
- }
+ if (!instance)
+ return -ENOMEM;
tphy->phys[port] = instance;
phy = devm_phy_create(dev, child_np, &mtk_tphy_ops);
if (IS_ERR(phy)) {
dev_err(dev, "failed to create phy\n");
- retval = PTR_ERR(phy);
- goto put_child;
+ return PTR_ERR(phy);
}
subdev = &phy->dev;
@@ -1649,14 +1646,12 @@ static int mtk_tphy_probe(struct platform_device *pdev)
if (retval) {
dev_err(subdev, "failed to get address resource(id-%d)\n",
port);
- goto put_child;
+ return retval;
}
instance->port_base = devm_ioremap_resource(subdev, &res);
- if (IS_ERR(instance->port_base)) {
- retval = PTR_ERR(instance->port_base);
- goto put_child;
- }
+ if (IS_ERR(instance->port_base))
+ return PTR_ERR(instance->port_base);
instance->phy = phy;
instance->index = port;
@@ -1668,19 +1663,16 @@ static int mtk_tphy_probe(struct platform_device *pdev)
clks[1].id = "da_ref"; /* analog clock */
retval = devm_clk_bulk_get_optional(subdev, TPHY_CLKS_CNT, clks);
if (retval)
- goto put_child;
+ return retval;
retval = phy_type_syscon_get(instance, child_np);
if (retval)
- goto put_child;
+ return retval;
}
provider = devm_of_phy_provider_register(dev, mtk_phy_xlate);
return PTR_ERR_OR_ZERO(provider);
-put_child:
- of_node_put(child_np);
- return retval;
}
static struct platform_driver mtk_tphy_driver = {
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH 06/11] phy: mediatek: xsphy: Simplify with scoped for each OF child loop
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
` (4 preceding siblings ...)
2024-08-26 10:07 ` [PATCH 05/11] phy: mediatek: tphy: " Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 07/11] phy: qcom: qmp-pcie-msm8996: " Krzysztof Kozlowski
` (5 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/mediatek/phy-mtk-xsphy.c | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
diff --git a/drivers/phy/mediatek/phy-mtk-xsphy.c b/drivers/phy/mediatek/phy-mtk-xsphy.c
index 064fd0941727..7c248f5cfca5 100644
--- a/drivers/phy/mediatek/phy-mtk-xsphy.c
+++ b/drivers/phy/mediatek/phy-mtk-xsphy.c
@@ -432,12 +432,11 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
- struct device_node *child_np;
struct phy_provider *provider;
struct resource *glb_res;
struct mtk_xsphy *xsphy;
struct resource res;
- int port, retval;
+ int port;
xsphy = devm_kzalloc(dev, sizeof(*xsphy), GFP_KERNEL);
if (!xsphy)
@@ -471,37 +470,34 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
device_property_read_u32(dev, "mediatek,src-coef", &xsphy->src_coef);
port = 0;
- for_each_child_of_node(np, child_np) {
+ for_each_child_of_node_scoped(np, child_np) {
struct xsphy_instance *inst;
struct phy *phy;
+ int retval;
inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL);
- if (!inst) {
- retval = -ENOMEM;
- goto put_child;
- }
+ if (!inst)
+ return -ENOMEM;
xsphy->phys[port] = inst;
phy = devm_phy_create(dev, child_np, &mtk_xsphy_ops);
if (IS_ERR(phy)) {
dev_err(dev, "failed to create phy\n");
- retval = PTR_ERR(phy);
- goto put_child;
+ return PTR_ERR(phy);
}
retval = of_address_to_resource(child_np, 0, &res);
if (retval) {
dev_err(dev, "failed to get address resource(id-%d)\n",
port);
- goto put_child;
+ return retval;
}
inst->port_base = devm_ioremap_resource(&phy->dev, &res);
if (IS_ERR(inst->port_base)) {
dev_err(dev, "failed to remap phy regs\n");
- retval = PTR_ERR(inst->port_base);
- goto put_child;
+ return PTR_ERR(inst->port_base);
}
inst->phy = phy;
@@ -512,17 +508,12 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
inst->ref_clk = devm_clk_get(&phy->dev, "ref");
if (IS_ERR(inst->ref_clk)) {
dev_err(dev, "failed to get ref_clk(id-%d)\n", port);
- retval = PTR_ERR(inst->ref_clk);
- goto put_child;
+ return PTR_ERR(inst->ref_clk);
}
}
provider = devm_of_phy_provider_register(dev, mtk_phy_xlate);
return PTR_ERR_OR_ZERO(provider);
-
-put_child:
- of_node_put(child_np);
- return retval;
}
static struct platform_driver mtk_xsphy_driver = {
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH 07/11] phy: qcom: qmp-pcie-msm8996: Simplify with scoped for each OF child loop
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
` (5 preceding siblings ...)
2024-08-26 10:07 ` [PATCH 06/11] phy: mediatek: xsphy: " Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-29 9:02 ` Dmitry Baryshkov
2024-08-26 10:07 ` [PATCH 08/11] phy: ti: am654-serdes: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
` (4 subsequent siblings)
11 siblings, 1 reply; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Use scoped for_each_available_child_of_node_scoped() when iterating over
device nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c b/drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c
index 5f89e3a3e54f..a7c65cfe31df 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c
@@ -725,7 +725,6 @@ static int qmp_pcie_msm8996_probe(struct platform_device *pdev)
{
struct qcom_qmp *qmp;
struct device *dev = &pdev->dev;
- struct device_node *child;
struct phy_provider *phy_provider;
void __iomem *serdes;
const struct qmp_phy_cfg *cfg = NULL;
@@ -773,13 +772,13 @@ static int qmp_pcie_msm8996_probe(struct platform_device *pdev)
return -ENOMEM;
id = 0;
- for_each_available_child_of_node(dev->of_node, child) {
+ for_each_available_child_of_node_scoped(dev->of_node, child) {
/* Create per-lane phy */
ret = qmp_pcie_msm8996_create(dev, child, id, serdes, cfg);
if (ret) {
dev_err(dev, "failed to create lane%d phy, %d\n",
id, ret);
- goto err_node_put;
+ return ret;
}
/*
@@ -790,7 +789,7 @@ static int qmp_pcie_msm8996_probe(struct platform_device *pdev)
if (ret) {
dev_err(qmp->dev,
"failed to register pipe clock source\n");
- goto err_node_put;
+ return ret;
}
id++;
@@ -799,10 +798,6 @@ static int qmp_pcie_msm8996_probe(struct platform_device *pdev)
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
return PTR_ERR_OR_ZERO(phy_provider);
-
-err_node_put:
- of_node_put(child);
- return ret;
}
static struct platform_driver qmp_pcie_msm8996_driver = {
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH 07/11] phy: qcom: qmp-pcie-msm8996: Simplify with scoped for each OF child loop
2024-08-26 10:07 ` [PATCH 07/11] phy: qcom: qmp-pcie-msm8996: " Krzysztof Kozlowski
@ 2024-08-29 9:02 ` Dmitry Baryshkov
0 siblings, 0 replies; 16+ messages in thread
From: Dmitry Baryshkov @ 2024-08-29 9:02 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno, linux-phy,
linux-arm-kernel, linux-kernel, linux-mediatek, linux-arm-msm
On Mon, Aug 26, 2024 at 12:07:23PM GMT, Krzysztof Kozlowski wrote:
> Use scoped for_each_available_child_of_node_scoped() when iterating over
> device nodes to make code a bit simpler.
>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> ---
> drivers/phy/qualcomm/phy-qcom-qmp-pcie-msm8996.c | 11 +++--------
> 1 file changed, 3 insertions(+), 8 deletions(-)
>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
--
With best wishes
Dmitry
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 08/11] phy: ti: am654-serdes: Use scoped device node handling to simplify error paths
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
` (6 preceding siblings ...)
2024-08-26 10:07 ` [PATCH 07/11] phy: qcom: qmp-pcie-msm8996: " Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 09/11] phy: ti: gmii-sel: Simplify with dev_err_probe() Krzysztof Kozlowski
` (3 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler.
Unlike in other typical of_node_get+syscon_node_to_regmap cases, the
reference cannot be dropped immediately after syscon_node_to_regmap(),
because further part of probe() uses it.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/ti/phy-am654-serdes.c | 50 +++++++++++++--------------------------
1 file changed, 17 insertions(+), 33 deletions(-)
diff --git a/drivers/phy/ti/phy-am654-serdes.c b/drivers/phy/ti/phy-am654-serdes.c
index 673449607c02..3bf3aff4b1c7 100644
--- a/drivers/phy/ti/phy-am654-serdes.c
+++ b/drivers/phy/ti/phy-am654-serdes.c
@@ -7,6 +7,7 @@
*/
#include <dt-bindings/phy/phy.h>
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/delay.h>
@@ -644,7 +645,6 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
struct device_node *node = am654_phy->of_node;
struct device *dev = am654_phy->dev;
struct serdes_am654_clk_mux *mux;
- struct device_node *regmap_node;
const char **parent_names;
struct clk_init_data *init;
unsigned int num_parents;
@@ -652,7 +652,6 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
const __be32 *addr;
unsigned int reg;
struct clk *clk;
- int ret = 0;
mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
if (!mux)
@@ -660,41 +659,30 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
init = &mux->clk_data;
- regmap_node = of_parse_phandle(node, "ti,serdes-clk", 0);
- if (!regmap_node) {
- dev_err(dev, "Fail to get serdes-clk node\n");
- ret = -ENODEV;
- goto out_put_node;
- }
+ struct device_node *regmap_node __free(device_node) =
+ of_parse_phandle(node, "ti,serdes-clk", 0);
+ if (!regmap_node)
+ return dev_err_probe(dev, -ENODEV, "Fail to get serdes-clk node\n");
regmap = syscon_node_to_regmap(regmap_node->parent);
- if (IS_ERR(regmap)) {
- dev_err(dev, "Fail to get Syscon regmap\n");
- ret = PTR_ERR(regmap);
- goto out_put_node;
- }
+ if (IS_ERR(regmap))
+ return dev_err_probe(dev, PTR_ERR(regmap),
+ "Fail to get Syscon regmap\n");
num_parents = of_clk_get_parent_count(node);
- if (num_parents < 2) {
- dev_err(dev, "SERDES clock must have parents\n");
- ret = -EINVAL;
- goto out_put_node;
- }
+ if (num_parents < 2)
+ return dev_err_probe(dev, -EINVAL, "SERDES clock must have parents\n");
parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents),
GFP_KERNEL);
- if (!parent_names) {
- ret = -ENOMEM;
- goto out_put_node;
- }
+ if (!parent_names)
+ return -ENOMEM;
of_clk_parent_fill(node, parent_names, num_parents);
addr = of_get_address(regmap_node, 0, NULL, NULL);
- if (!addr) {
- ret = -EINVAL;
- goto out_put_node;
- }
+ if (!addr)
+ return -EINVAL;
reg = be32_to_cpu(*addr);
@@ -710,16 +698,12 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
mux->hw.init = init;
clk = devm_clk_register(dev, &mux->hw);
- if (IS_ERR(clk)) {
- ret = PTR_ERR(clk);
- goto out_put_node;
- }
+ if (IS_ERR(clk))
+ return PTR_ERR(clk);
am654_phy->clks[clock_num] = clk;
-out_put_node:
- of_node_put(regmap_node);
- return ret;
+ return 0;
}
static const struct of_device_id serdes_am654_id_table[] = {
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH 09/11] phy: ti: gmii-sel: Simplify with dev_err_probe()
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
` (7 preceding siblings ...)
2024-08-26 10:07 ` [PATCH 08/11] phy: ti: am654-serdes: Use scoped device node handling to simplify error paths Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 10/11] phy: ti: j721e-wiz: Drop OF node reference earlier for simpler code Krzysztof Kozlowski
` (2 subsequent siblings)
11 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Use dev_err_probe() to avoid dmesg flood on actual defer. This makes
the code also simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/ti/phy-gmii-sel.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/drivers/phy/ti/phy-gmii-sel.c b/drivers/phy/ti/phy-gmii-sel.c
index b30bf740e2e0..103b266fec77 100644
--- a/drivers/phy/ti/phy-gmii-sel.c
+++ b/drivers/phy/ti/phy-gmii-sel.c
@@ -468,11 +468,9 @@ static int phy_gmii_sel_probe(struct platform_device *pdev)
priv->regmap = syscon_node_to_regmap(node->parent);
if (IS_ERR(priv->regmap)) {
priv->regmap = device_node_to_regmap(node);
- if (IS_ERR(priv->regmap)) {
- ret = PTR_ERR(priv->regmap);
- dev_err(dev, "Failed to get syscon %d\n", ret);
- return ret;
- }
+ if (IS_ERR(priv->regmap))
+ return dev_err_probe(dev, PTR_ERR(priv->regmap),
+ "Failed to get syscon\n");
priv->no_offset = true;
}
@@ -485,11 +483,9 @@ static int phy_gmii_sel_probe(struct platform_device *pdev)
priv->phy_provider =
devm_of_phy_provider_register(dev,
phy_gmii_sel_of_xlate);
- if (IS_ERR(priv->phy_provider)) {
- ret = PTR_ERR(priv->phy_provider);
- dev_err(dev, "Failed to create phy provider %d\n", ret);
- return ret;
- }
+ if (IS_ERR(priv->phy_provider))
+ return dev_err_probe(dev, PTR_ERR(priv->phy_provider),
+ "Failed to create phy provider\n");
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH 10/11] phy: ti: j721e-wiz: Drop OF node reference earlier for simpler code
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
` (8 preceding siblings ...)
2024-08-26 10:07 ` [PATCH 09/11] phy: ti: gmii-sel: Simplify with dev_err_probe() Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-26 10:07 ` [PATCH 11/11] phy: ti: j721e-wiz: Simplify with scoped for each OF child loop Krzysztof Kozlowski
2024-08-30 8:10 ` [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Vinod Koul
11 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Drop OF node reference immediately after using it in
syscon_node_to_regmap(), which is both simpler and typical/expected
code pattern.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/ti/phy-j721e-wiz.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/phy/ti/phy-j721e-wiz.c b/drivers/phy/ti/phy-j721e-wiz.c
index bb16fdfe63df..d0f3ead3fc80 100644
--- a/drivers/phy/ti/phy-j721e-wiz.c
+++ b/drivers/phy/ti/phy-j721e-wiz.c
@@ -1179,14 +1179,13 @@ static int wiz_clock_probe(struct wiz *wiz, struct device_node *node)
ret = wiz_mux_of_clk_register(wiz, clk_node, wiz->mux_sel_field[i],
clk_mux_sel[i].table);
+ of_node_put(clk_node);
if (ret) {
dev_err_probe(dev, ret, "Failed to register %s clock\n",
node_name);
- of_node_put(clk_node);
goto err;
}
- of_node_put(clk_node);
}
for (i = 0; i < wiz->clk_div_sel_num; i++) {
@@ -1199,14 +1198,12 @@ static int wiz_clock_probe(struct wiz *wiz, struct device_node *node)
ret = wiz_div_clk_register(wiz, clk_node, wiz->div_sel_field[i],
clk_div_sel[i].table);
+ of_node_put(clk_node);
if (ret) {
dev_err_probe(dev, ret, "Failed to register %s clock\n",
node_name);
- of_node_put(clk_node);
goto err;
}
-
- of_node_put(clk_node);
}
return 0;
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* [PATCH 11/11] phy: ti: j721e-wiz: Simplify with scoped for each OF child loop
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
` (9 preceding siblings ...)
2024-08-26 10:07 ` [PATCH 10/11] phy: ti: j721e-wiz: Drop OF node reference earlier for simpler code Krzysztof Kozlowski
@ 2024-08-26 10:07 ` Krzysztof Kozlowski
2024-08-30 8:10 ` [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Vinod Koul
11 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2024-08-26 10:07 UTC (permalink / raw)
To: Vinod Koul, Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm, Krzysztof Kozlowski
Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
drivers/phy/ti/phy-j721e-wiz.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/phy/ti/phy-j721e-wiz.c b/drivers/phy/ti/phy-j721e-wiz.c
index d0f3ead3fc80..a6c0c5607ffd 100644
--- a/drivers/phy/ti/phy-j721e-wiz.c
+++ b/drivers/phy/ti/phy-j721e-wiz.c
@@ -1404,7 +1404,7 @@ MODULE_DEVICE_TABLE(of, wiz_id_table);
static int wiz_get_lane_phy_types(struct device *dev, struct wiz *wiz)
{
- struct device_node *serdes, *subnode;
+ struct device_node *serdes;
serdes = of_get_child_by_name(dev->of_node, "serdes");
if (!serdes) {
@@ -1412,7 +1412,7 @@ static int wiz_get_lane_phy_types(struct device *dev, struct wiz *wiz)
return -EINVAL;
}
- for_each_child_of_node(serdes, subnode) {
+ for_each_child_of_node_scoped(serdes, subnode) {
u32 reg, num_lanes = 1, phy_type = PHY_NONE;
int ret, i;
@@ -1422,7 +1422,6 @@ static int wiz_get_lane_phy_types(struct device *dev, struct wiz *wiz)
ret = of_property_read_u32(subnode, "reg", ®);
if (ret) {
- of_node_put(subnode);
dev_err(dev,
"%s: Reading \"reg\" from \"%s\" failed: %d\n",
__func__, subnode->name, ret);
--
2.43.0
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH 00/11] phy: simplify with cleanup.h and few other ideas
2024-08-26 10:07 [PATCH 00/11] phy: simplify with cleanup.h and few other ideas Krzysztof Kozlowski
` (10 preceding siblings ...)
2024-08-26 10:07 ` [PATCH 11/11] phy: ti: j721e-wiz: Simplify with scoped for each OF child loop Krzysztof Kozlowski
@ 2024-08-30 8:10 ` Vinod Koul
11 siblings, 0 replies; 16+ messages in thread
From: Vinod Koul @ 2024-08-30 8:10 UTC (permalink / raw)
To: Kishon Vijay Abraham I, Ray Jui, Scott Branden,
Broadcom internal kernel review list, Chunfeng Yun,
Matthias Brugger, AngeloGioacchino Del Regno, Krzysztof Kozlowski
Cc: linux-phy, linux-arm-kernel, linux-kernel, linux-mediatek,
linux-arm-msm
On Mon, 26 Aug 2024 12:07:16 +0200, Krzysztof Kozlowski wrote:
> Make code simpler with scoped/cleanup.h/dev_err_probe.
>
> Best regards,
> Krzysztof
>
Applied, thanks!
[01/11] phy: broadcom: bcm-cygnus-pcie: Simplify with scoped for each OF child loop
commit: e33525de6c3c7780564e0859ea6daef27309995b
[02/11] phy: broadcom: brcm-sata: Simplify with scoped for each OF child loop
commit: a7f1dbf479d2a3cbf2a25bd186bbe15efd17d849
[03/11] phy: cadence: sierra: Simplify with scoped for each OF child loop
commit: 612f9fcb435fdc9abd46b6339c9000cef6d323a2
[04/11] phy: hisilicon: usb2: Simplify with scoped for each OF child loop
commit: 93cab07a02f08e4a2837dd22280b741ba0a7a541
[05/11] phy: mediatek: tphy: Simplify with scoped for each OF child loop
commit: d2714416770ed0cecaf69eaff34d20817f2c3bea
[06/11] phy: mediatek: xsphy: Simplify with scoped for each OF child loop
commit: 77df35acd182a23c117a937ffd6b0830a5428649
[07/11] phy: qcom: qmp-pcie-msm8996: Simplify with scoped for each OF child loop
commit: 608863e1e600a4d91b00dddd6ff11eda1cbebaa5
[08/11] phy: ti: am654-serdes: Use scoped device node handling to simplify error paths
commit: 29b44a38503856952862c710d47d933c0173fd04
[09/11] phy: ti: gmii-sel: Simplify with dev_err_probe()
commit: 27a4046255377eb0faab5c41fd271b1acab1ac41
[10/11] phy: ti: j721e-wiz: Drop OF node reference earlier for simpler code
commit: afd7aaf3ecaf1b247db1294ef0687fb3cb530213
[11/11] phy: ti: j721e-wiz: Simplify with scoped for each OF child loop
commit: 0d5a213c2eae880e0f7f8bc252314bae194d68d8
Best regards,
--
~Vinod
^ permalink raw reply [flat|nested] 16+ messages in thread