Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

+35 -53
+2 -3
drivers/net/dsa/microchip/ksz_common.c
··· 4717 4717 int ksz_switch_register(struct ksz_device *dev) 4718 4718 { 4719 4719 const struct ksz_chip_data *info; 4720 - struct device_node *port, *ports; 4720 + struct device_node *ports; 4721 4721 phy_interface_t interface; 4722 4722 unsigned int port_num; 4723 4723 int ret; ··· 4803 4803 if (!ports) 4804 4804 ports = of_get_child_by_name(dev->dev->of_node, "ports"); 4805 4805 if (ports) { 4806 - for_each_available_child_of_node(ports, port) { 4806 + for_each_available_child_of_node_scoped(ports, port) { 4807 4807 if (of_property_read_u32(port, "reg", 4808 4808 &port_num)) 4809 4809 continue; 4810 4810 if (!(dev->port_mask & BIT(port_num))) { 4811 - of_node_put(port); 4812 4811 of_node_put(ports); 4813 4812 return -EINVAL; 4814 4813 }
+3 -5
drivers/net/dsa/realtek/rtl8366rb.c
··· 1009 1009 1010 1010 static int rtl8366rb_setup_leds(struct realtek_priv *priv) 1011 1011 { 1012 - struct device_node *leds_np, *led_np; 1013 1012 struct dsa_switch *ds = &priv->ds; 1013 + struct device_node *leds_np; 1014 1014 struct dsa_port *dp; 1015 1015 int ret = 0; 1016 1016 ··· 1025 1025 continue; 1026 1026 } 1027 1027 1028 - for_each_child_of_node(leds_np, led_np) { 1028 + for_each_child_of_node_scoped(leds_np, led_np) { 1029 1029 ret = rtl8366rb_setup_led(priv, dp, 1030 1030 of_fwnode_handle(led_np)); 1031 - if (ret) { 1032 - of_node_put(led_np); 1031 + if (ret) 1033 1032 break; 1034 - } 1035 1033 } 1036 1034 1037 1035 of_node_put(leds_np);
+2 -3
drivers/net/ethernet/broadcom/asp2/bcmasp.c
··· 1300 1300 1301 1301 static int bcmasp_probe(struct platform_device *pdev) 1302 1302 { 1303 - struct device_node *ports_node, *intf_node; 1304 1303 const struct bcmasp_plat_data *pdata; 1305 1304 struct device *dev = &pdev->dev; 1305 + struct device_node *ports_node; 1306 1306 struct bcmasp_priv *priv; 1307 1307 struct bcmasp_intf *intf; 1308 1308 int ret = 0, count = 0; ··· 1374 1374 } 1375 1375 1376 1376 i = 0; 1377 - for_each_available_child_of_node(ports_node, intf_node) { 1377 + for_each_available_child_of_node_scoped(ports_node, intf_node) { 1378 1378 intf = bcmasp_interface_create(priv, intf_node, i); 1379 1379 if (!intf) { 1380 1380 dev_err(dev, "Cannot create eth interface %d\n", i); 1381 1381 bcmasp_remove_intfs(priv); 1382 - of_node_put(intf_node); 1383 1382 ret = -ENOMEM; 1384 1383 goto of_put_exit; 1385 1384 }
+2 -3
drivers/net/ethernet/marvell/mv643xx_eth.c
··· 2802 2802 static int mv643xx_eth_shared_of_probe(struct platform_device *pdev) 2803 2803 { 2804 2804 struct mv643xx_eth_shared_platform_data *pd; 2805 - struct device_node *pnp, *np = pdev->dev.of_node; 2805 + struct device_node *np = pdev->dev.of_node; 2806 2806 int ret; 2807 2807 2808 2808 /* bail out if not registered from DT */ ··· 2816 2816 2817 2817 mv643xx_eth_property(np, "tx-checksum-limit", pd->tx_csum_limit); 2818 2818 2819 - for_each_available_child_of_node(np, pnp) { 2819 + for_each_available_child_of_node_scoped(np, pnp) { 2820 2820 ret = mv643xx_eth_shared_of_add_port(pdev, pnp); 2821 2821 if (ret) { 2822 - of_node_put(pnp); 2823 2822 mv643xx_eth_shared_of_remove(); 2824 2823 return ret; 2825 2824 }
+2 -4
drivers/net/ethernet/stmicro/stmmac/dwmac-sun8i.c
··· 774 774 static int get_ephy_nodes(struct stmmac_priv *priv) 775 775 { 776 776 struct sunxi_priv_data *gmac = priv->plat->bsp_priv; 777 - struct device_node *mdio_mux, *iphynode; 778 777 struct device_node *mdio_internal; 778 + struct device_node *mdio_mux; 779 779 int ret; 780 780 781 781 mdio_mux = of_get_child_by_name(priv->device->of_node, "mdio-mux"); ··· 793 793 } 794 794 795 795 /* Seek for internal PHY */ 796 - for_each_child_of_node(mdio_internal, iphynode) { 796 + for_each_child_of_node_scoped(mdio_internal, iphynode) { 797 797 gmac->ephy_clk = of_clk_get(iphynode, 0); 798 798 if (IS_ERR(gmac->ephy_clk)) 799 799 continue; ··· 801 801 if (IS_ERR(gmac->rst_ephy)) { 802 802 ret = PTR_ERR(gmac->rst_ephy); 803 803 if (ret == -EPROBE_DEFER) { 804 - of_node_put(iphynode); 805 804 of_node_put(mdio_internal); 806 805 return ret; 807 806 } 808 807 continue; 809 808 } 810 809 dev_info(priv->device, "Found internal PHY node\n"); 811 - of_node_put(iphynode); 812 810 of_node_put(mdio_internal); 813 811 return 0; 814 812 }
+22 -32
drivers/net/mdio/mdio-mux-mmioreg.c
··· 96 96 97 97 static int mdio_mux_mmioreg_probe(struct platform_device *pdev) 98 98 { 99 - struct device_node *np2, *np = pdev->dev.of_node; 99 + struct device_node *np = pdev->dev.of_node; 100 100 struct mdio_mux_mmioreg_state *s; 101 101 struct resource res; 102 102 const __be32 *iprop; ··· 109 109 return -ENOMEM; 110 110 111 111 ret = of_address_to_resource(np, 0, &res); 112 - if (ret) { 113 - dev_err(&pdev->dev, "could not obtain memory map for node %pOF\n", 114 - np); 115 - return ret; 116 - } 112 + if (ret) 113 + return dev_err_probe(&pdev->dev, ret, 114 + "could not obtain memory map for node %pOF\n", np); 117 115 s->phys = res.start; 118 116 119 117 s->iosize = resource_size(&res); 120 118 if (s->iosize != sizeof(uint8_t) && 121 119 s->iosize != sizeof(uint16_t) && 122 - s->iosize != sizeof(uint32_t)) { 123 - dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n"); 124 - return -EINVAL; 125 - } 120 + s->iosize != sizeof(uint32_t)) 121 + return dev_err_probe(&pdev->dev, -EINVAL, 122 + "only 8/16/32-bit registers are supported\n"); 126 123 127 124 iprop = of_get_property(np, "mux-mask", &len); 128 - if (!iprop || len != sizeof(uint32_t)) { 129 - dev_err(&pdev->dev, "missing or invalid mux-mask property\n"); 130 - return -ENODEV; 131 - } 132 - if (be32_to_cpup(iprop) >= BIT(s->iosize * 8)) { 133 - dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n"); 134 - return -EINVAL; 135 - } 125 + if (!iprop || len != sizeof(uint32_t)) 126 + return dev_err_probe(&pdev->dev, -ENODEV, 127 + "missing or invalid mux-mask property\n"); 128 + if (be32_to_cpup(iprop) >= BIT(s->iosize * 8)) 129 + return dev_err_probe(&pdev->dev, -EINVAL, 130 + "only 8/16/32-bit registers are supported\n"); 136 131 s->mask = be32_to_cpup(iprop); 137 132 138 133 /* 139 134 * Verify that the 'reg' property of each child MDIO bus does not 140 135 * set any bits outside of the 'mask'. 141 136 */ 142 - for_each_available_child_of_node(np, np2) { 137 + for_each_available_child_of_node_scoped(np, np2) { 143 138 u64 reg; 144 139 145 - if (of_property_read_reg(np2, 0, &reg, NULL)) { 146 - dev_err(&pdev->dev, "mdio-mux child node %pOF is " 147 - "missing a 'reg' property\n", np2); 148 - of_node_put(np2); 149 - return -ENODEV; 150 - } 151 - if ((u32)reg & ~s->mask) { 152 - dev_err(&pdev->dev, "mdio-mux child node %pOF has " 153 - "a 'reg' value with unmasked bits\n", 154 - np2); 155 - of_node_put(np2); 156 - return -ENODEV; 157 - } 140 + if (of_property_read_reg(np2, 0, &reg, NULL)) 141 + return dev_err_probe(&pdev->dev, -ENODEV, 142 + "mdio-mux child node %pOF is missing a 'reg' property\n", 143 + np2); 144 + if ((u32)reg & ~s->mask) 145 + return dev_err_probe(&pdev->dev, -ENODEV, 146 + "mdio-mux child node %pOF has a 'reg' value with unmasked bits\n", 147 + np2); 158 148 } 159 149 160 150 ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node,
+2 -3
drivers/net/phy/phy_device.c
··· 3407 3407 static int of_phy_leds(struct phy_device *phydev) 3408 3408 { 3409 3409 struct device_node *node = phydev->mdio.dev.of_node; 3410 - struct device_node *leds, *led; 3410 + struct device_node *leds; 3411 3411 int err; 3412 3412 3413 3413 if (!IS_ENABLED(CONFIG_OF_MDIO)) ··· 3420 3420 if (!leds) 3421 3421 return 0; 3422 3422 3423 - for_each_available_child_of_node(leds, led) { 3423 + for_each_available_child_of_node_scoped(leds, led) { 3424 3424 err = of_phy_led(phydev, led); 3425 3425 if (err) { 3426 - of_node_put(led); 3427 3426 phy_leds_unregister(phydev); 3428 3427 return err; 3429 3428 }