Commit 4c93b0bc authored by Paolo Abeni's avatar Paolo Abeni

Merge branch 'net-simplified-with-scoped-function'

Jinjie Ruan says:

====================
net: Simplified with scoped function

Simplify with scoped for each OF child loop, as well as dev_err_probe().

Changes in v4:
- Drop the fix patch and __free() patch.
- Rebased on the fix patch has been stripped out.
- Remove the extra parentheses.
- Ensure Signed-off-by: should always be last.
- Add Reviewed-by.
- Update the cover letter commit message.

Changes in v3:
- Sort the variables, longest first, shortest last.
- Add Reviewed-by.

Changes in v2:
- Subject prefix: next -> net-next.
- Split __free() from scoped for each OF child loop clean.
- Fix use of_node_put() instead of __free() for the 5th patch.
====================

Link: https://patch.msgid.link/20240830031325.2406672-1-ruanjinjie@huawei.comSigned-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents c55f34a7 e8ac8974
...@@ -4717,7 +4717,7 @@ static int ksz_parse_drive_strength(struct ksz_device *dev) ...@@ -4717,7 +4717,7 @@ static int ksz_parse_drive_strength(struct ksz_device *dev)
int ksz_switch_register(struct ksz_device *dev) int ksz_switch_register(struct ksz_device *dev)
{ {
const struct ksz_chip_data *info; const struct ksz_chip_data *info;
struct device_node *port, *ports; struct device_node *ports;
phy_interface_t interface; phy_interface_t interface;
unsigned int port_num; unsigned int port_num;
int ret; int ret;
...@@ -4803,12 +4803,11 @@ int ksz_switch_register(struct ksz_device *dev) ...@@ -4803,12 +4803,11 @@ int ksz_switch_register(struct ksz_device *dev)
if (!ports) if (!ports)
ports = of_get_child_by_name(dev->dev->of_node, "ports"); ports = of_get_child_by_name(dev->dev->of_node, "ports");
if (ports) { if (ports) {
for_each_available_child_of_node(ports, port) { for_each_available_child_of_node_scoped(ports, port) {
if (of_property_read_u32(port, "reg", if (of_property_read_u32(port, "reg",
&port_num)) &port_num))
continue; continue;
if (!(dev->port_mask & BIT(port_num))) { if (!(dev->port_mask & BIT(port_num))) {
of_node_put(port);
of_node_put(ports); of_node_put(ports);
return -EINVAL; return -EINVAL;
} }
......
...@@ -1009,8 +1009,8 @@ static int rtl8366rb_setup_all_leds_off(struct realtek_priv *priv) ...@@ -1009,8 +1009,8 @@ static int rtl8366rb_setup_all_leds_off(struct realtek_priv *priv)
static int rtl8366rb_setup_leds(struct realtek_priv *priv) static int rtl8366rb_setup_leds(struct realtek_priv *priv)
{ {
struct device_node *leds_np, *led_np;
struct dsa_switch *ds = &priv->ds; struct dsa_switch *ds = &priv->ds;
struct device_node *leds_np;
struct dsa_port *dp; struct dsa_port *dp;
int ret = 0; int ret = 0;
...@@ -1025,14 +1025,12 @@ static int rtl8366rb_setup_leds(struct realtek_priv *priv) ...@@ -1025,14 +1025,12 @@ static int rtl8366rb_setup_leds(struct realtek_priv *priv)
continue; continue;
} }
for_each_child_of_node(leds_np, led_np) { for_each_child_of_node_scoped(leds_np, led_np) {
ret = rtl8366rb_setup_led(priv, dp, ret = rtl8366rb_setup_led(priv, dp,
of_fwnode_handle(led_np)); of_fwnode_handle(led_np));
if (ret) { if (ret)
of_node_put(led_np);
break; break;
} }
}
of_node_put(leds_np); of_node_put(leds_np);
if (ret) if (ret)
......
...@@ -1300,9 +1300,9 @@ static void bcmasp_remove_intfs(struct bcmasp_priv *priv) ...@@ -1300,9 +1300,9 @@ static void bcmasp_remove_intfs(struct bcmasp_priv *priv)
static int bcmasp_probe(struct platform_device *pdev) static int bcmasp_probe(struct platform_device *pdev)
{ {
struct device_node *ports_node, *intf_node;
const struct bcmasp_plat_data *pdata; const struct bcmasp_plat_data *pdata;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *ports_node;
struct bcmasp_priv *priv; struct bcmasp_priv *priv;
struct bcmasp_intf *intf; struct bcmasp_intf *intf;
int ret = 0, count = 0; int ret = 0, count = 0;
...@@ -1374,12 +1374,11 @@ static int bcmasp_probe(struct platform_device *pdev) ...@@ -1374,12 +1374,11 @@ static int bcmasp_probe(struct platform_device *pdev)
} }
i = 0; i = 0;
for_each_available_child_of_node(ports_node, intf_node) { for_each_available_child_of_node_scoped(ports_node, intf_node) {
intf = bcmasp_interface_create(priv, intf_node, i); intf = bcmasp_interface_create(priv, intf_node, i);
if (!intf) { if (!intf) {
dev_err(dev, "Cannot create eth interface %d\n", i); dev_err(dev, "Cannot create eth interface %d\n", i);
bcmasp_remove_intfs(priv); bcmasp_remove_intfs(priv);
of_node_put(intf_node);
ret = -ENOMEM; ret = -ENOMEM;
goto of_put_exit; goto of_put_exit;
} }
......
...@@ -2802,7 +2802,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev, ...@@ -2802,7 +2802,7 @@ static int mv643xx_eth_shared_of_add_port(struct platform_device *pdev,
static int mv643xx_eth_shared_of_probe(struct platform_device *pdev) static int mv643xx_eth_shared_of_probe(struct platform_device *pdev)
{ {
struct mv643xx_eth_shared_platform_data *pd; struct mv643xx_eth_shared_platform_data *pd;
struct device_node *pnp, *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
int ret; int ret;
/* bail out if not registered from DT */ /* bail out if not registered from DT */
...@@ -2816,10 +2816,9 @@ static int mv643xx_eth_shared_of_probe(struct platform_device *pdev) ...@@ -2816,10 +2816,9 @@ static int mv643xx_eth_shared_of_probe(struct platform_device *pdev)
mv643xx_eth_property(np, "tx-checksum-limit", pd->tx_csum_limit); mv643xx_eth_property(np, "tx-checksum-limit", pd->tx_csum_limit);
for_each_available_child_of_node(np, pnp) { for_each_available_child_of_node_scoped(np, pnp) {
ret = mv643xx_eth_shared_of_add_port(pdev, pnp); ret = mv643xx_eth_shared_of_add_port(pdev, pnp);
if (ret) { if (ret) {
of_node_put(pnp);
mv643xx_eth_shared_of_remove(); mv643xx_eth_shared_of_remove();
return ret; return ret;
} }
......
...@@ -774,8 +774,8 @@ static int sun8i_dwmac_reset(struct stmmac_priv *priv) ...@@ -774,8 +774,8 @@ static int sun8i_dwmac_reset(struct stmmac_priv *priv)
static int get_ephy_nodes(struct stmmac_priv *priv) static int get_ephy_nodes(struct stmmac_priv *priv)
{ {
struct sunxi_priv_data *gmac = priv->plat->bsp_priv; struct sunxi_priv_data *gmac = priv->plat->bsp_priv;
struct device_node *mdio_mux, *iphynode;
struct device_node *mdio_internal; struct device_node *mdio_internal;
struct device_node *mdio_mux;
int ret; int ret;
mdio_mux = of_get_child_by_name(priv->device->of_node, "mdio-mux"); mdio_mux = of_get_child_by_name(priv->device->of_node, "mdio-mux");
...@@ -793,7 +793,7 @@ static int get_ephy_nodes(struct stmmac_priv *priv) ...@@ -793,7 +793,7 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
} }
/* Seek for internal PHY */ /* Seek for internal PHY */
for_each_child_of_node(mdio_internal, iphynode) { for_each_child_of_node_scoped(mdio_internal, iphynode) {
gmac->ephy_clk = of_clk_get(iphynode, 0); gmac->ephy_clk = of_clk_get(iphynode, 0);
if (IS_ERR(gmac->ephy_clk)) if (IS_ERR(gmac->ephy_clk))
continue; continue;
...@@ -801,14 +801,12 @@ static int get_ephy_nodes(struct stmmac_priv *priv) ...@@ -801,14 +801,12 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
if (IS_ERR(gmac->rst_ephy)) { if (IS_ERR(gmac->rst_ephy)) {
ret = PTR_ERR(gmac->rst_ephy); ret = PTR_ERR(gmac->rst_ephy);
if (ret == -EPROBE_DEFER) { if (ret == -EPROBE_DEFER) {
of_node_put(iphynode);
of_node_put(mdio_internal); of_node_put(mdio_internal);
return ret; return ret;
} }
continue; continue;
} }
dev_info(priv->device, "Found internal PHY node\n"); dev_info(priv->device, "Found internal PHY node\n");
of_node_put(iphynode);
of_node_put(mdio_internal); of_node_put(mdio_internal);
return 0; return 0;
} }
......
...@@ -96,7 +96,7 @@ static int mdio_mux_mmioreg_switch_fn(int current_child, int desired_child, ...@@ -96,7 +96,7 @@ static int mdio_mux_mmioreg_switch_fn(int current_child, int desired_child,
static int mdio_mux_mmioreg_probe(struct platform_device *pdev) static int mdio_mux_mmioreg_probe(struct platform_device *pdev)
{ {
struct device_node *np2, *np = pdev->dev.of_node; struct device_node *np = pdev->dev.of_node;
struct mdio_mux_mmioreg_state *s; struct mdio_mux_mmioreg_state *s;
struct resource res; struct resource res;
const __be32 *iprop; const __be32 *iprop;
...@@ -109,52 +109,42 @@ static int mdio_mux_mmioreg_probe(struct platform_device *pdev) ...@@ -109,52 +109,42 @@ static int mdio_mux_mmioreg_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
ret = of_address_to_resource(np, 0, &res); ret = of_address_to_resource(np, 0, &res);
if (ret) { if (ret)
dev_err(&pdev->dev, "could not obtain memory map for node %pOF\n", return dev_err_probe(&pdev->dev, ret,
np); "could not obtain memory map for node %pOF\n", np);
return ret;
}
s->phys = res.start; s->phys = res.start;
s->iosize = resource_size(&res); s->iosize = resource_size(&res);
if (s->iosize != sizeof(uint8_t) && if (s->iosize != sizeof(uint8_t) &&
s->iosize != sizeof(uint16_t) && s->iosize != sizeof(uint16_t) &&
s->iosize != sizeof(uint32_t)) { s->iosize != sizeof(uint32_t))
dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n"); return dev_err_probe(&pdev->dev, -EINVAL,
return -EINVAL; "only 8/16/32-bit registers are supported\n");
}
iprop = of_get_property(np, "mux-mask", &len); iprop = of_get_property(np, "mux-mask", &len);
if (!iprop || len != sizeof(uint32_t)) { if (!iprop || len != sizeof(uint32_t))
dev_err(&pdev->dev, "missing or invalid mux-mask property\n"); return dev_err_probe(&pdev->dev, -ENODEV,
return -ENODEV; "missing or invalid mux-mask property\n");
} if (be32_to_cpup(iprop) >= BIT(s->iosize * 8))
if (be32_to_cpup(iprop) >= BIT(s->iosize * 8)) { return dev_err_probe(&pdev->dev, -EINVAL,
dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n"); "only 8/16/32-bit registers are supported\n");
return -EINVAL;
}
s->mask = be32_to_cpup(iprop); s->mask = be32_to_cpup(iprop);
/* /*
* Verify that the 'reg' property of each child MDIO bus does not * Verify that the 'reg' property of each child MDIO bus does not
* set any bits outside of the 'mask'. * set any bits outside of the 'mask'.
*/ */
for_each_available_child_of_node(np, np2) { for_each_available_child_of_node_scoped(np, np2) {
u64 reg; u64 reg;
if (of_property_read_reg(np2, 0, &reg, NULL)) { if (of_property_read_reg(np2, 0, &reg, NULL))
dev_err(&pdev->dev, "mdio-mux child node %pOF is " return dev_err_probe(&pdev->dev, -ENODEV,
"missing a 'reg' property\n", np2); "mdio-mux child node %pOF is missing a 'reg' property\n",
of_node_put(np2); np2);
return -ENODEV; if ((u32)reg & ~s->mask)
} return dev_err_probe(&pdev->dev, -ENODEV,
if ((u32)reg & ~s->mask) { "mdio-mux child node %pOF has a 'reg' value with unmasked bits\n",
dev_err(&pdev->dev, "mdio-mux child node %pOF has "
"a 'reg' value with unmasked bits\n",
np2); np2);
of_node_put(np2);
return -ENODEV;
}
} }
ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node, ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node,
......
...@@ -3407,7 +3407,7 @@ static int of_phy_led(struct phy_device *phydev, ...@@ -3407,7 +3407,7 @@ static int of_phy_led(struct phy_device *phydev,
static int of_phy_leds(struct phy_device *phydev) static int of_phy_leds(struct phy_device *phydev)
{ {
struct device_node *node = phydev->mdio.dev.of_node; struct device_node *node = phydev->mdio.dev.of_node;
struct device_node *leds, *led; struct device_node *leds;
int err; int err;
if (!IS_ENABLED(CONFIG_OF_MDIO)) if (!IS_ENABLED(CONFIG_OF_MDIO))
...@@ -3420,10 +3420,9 @@ static int of_phy_leds(struct phy_device *phydev) ...@@ -3420,10 +3420,9 @@ static int of_phy_leds(struct phy_device *phydev)
if (!leds) if (!leds)
return 0; return 0;
for_each_available_child_of_node(leds, led) { for_each_available_child_of_node_scoped(leds, led) {
err = of_phy_led(phydev, led); err = of_phy_led(phydev, led);
if (err) { if (err) {
of_node_put(led);
phy_leds_unregister(phydev); phy_leds_unregister(phydev);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment