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)
int ksz_switch_register(struct ksz_device *dev)
{
const struct ksz_chip_data *info;
struct device_node *port, *ports;
struct device_node *ports;
phy_interface_t interface;
unsigned int port_num;
int ret;
......@@ -4803,12 +4803,11 @@ int ksz_switch_register(struct ksz_device *dev)
if (!ports)
ports = of_get_child_by_name(dev->dev->of_node, "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",
&port_num))
continue;
if (!(dev->port_mask & BIT(port_num))) {
of_node_put(port);
of_node_put(ports);
return -EINVAL;
}
......
......@@ -1009,8 +1009,8 @@ static int rtl8366rb_setup_all_leds_off(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 device_node *leds_np;
struct dsa_port *dp;
int ret = 0;
......@@ -1025,13 +1025,11 @@ static int rtl8366rb_setup_leds(struct realtek_priv *priv)
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,
of_fwnode_handle(led_np));
if (ret) {
of_node_put(led_np);
if (ret)
break;
}
}
of_node_put(leds_np);
......
......@@ -1300,9 +1300,9 @@ static void bcmasp_remove_intfs(struct bcmasp_priv *priv)
static int bcmasp_probe(struct platform_device *pdev)
{
struct device_node *ports_node, *intf_node;
const struct bcmasp_plat_data *pdata;
struct device *dev = &pdev->dev;
struct device_node *ports_node;
struct bcmasp_priv *priv;
struct bcmasp_intf *intf;
int ret = 0, count = 0;
......@@ -1374,12 +1374,11 @@ static int bcmasp_probe(struct platform_device *pdev)
}
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);
if (!intf) {
dev_err(dev, "Cannot create eth interface %d\n", i);
bcmasp_remove_intfs(priv);
of_node_put(intf_node);
ret = -ENOMEM;
goto of_put_exit;
}
......
......@@ -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)
{
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;
/* bail out if not registered from DT */
......@@ -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);
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);
if (ret) {
of_node_put(pnp);
mv643xx_eth_shared_of_remove();
return ret;
}
......
......@@ -774,8 +774,8 @@ static int sun8i_dwmac_reset(struct stmmac_priv *priv)
static int get_ephy_nodes(struct stmmac_priv *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_mux;
int ret;
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)
}
/* 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);
if (IS_ERR(gmac->ephy_clk))
continue;
......@@ -801,14 +801,12 @@ static int get_ephy_nodes(struct stmmac_priv *priv)
if (IS_ERR(gmac->rst_ephy)) {
ret = PTR_ERR(gmac->rst_ephy);
if (ret == -EPROBE_DEFER) {
of_node_put(iphynode);
of_node_put(mdio_internal);
return ret;
}
continue;
}
dev_info(priv->device, "Found internal PHY node\n");
of_node_put(iphynode);
of_node_put(mdio_internal);
return 0;
}
......
......@@ -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)
{
struct device_node *np2, *np = pdev->dev.of_node;
struct device_node *np = pdev->dev.of_node;
struct mdio_mux_mmioreg_state *s;
struct resource res;
const __be32 *iprop;
......@@ -109,52 +109,42 @@ static int mdio_mux_mmioreg_probe(struct platform_device *pdev)
return -ENOMEM;
ret = of_address_to_resource(np, 0, &res);
if (ret) {
dev_err(&pdev->dev, "could not obtain memory map for node %pOF\n",
np);
return ret;
}
if (ret)
return dev_err_probe(&pdev->dev, ret,
"could not obtain memory map for node %pOF\n", np);
s->phys = res.start;
s->iosize = resource_size(&res);
if (s->iosize != sizeof(uint8_t) &&
s->iosize != sizeof(uint16_t) &&
s->iosize != sizeof(uint32_t)) {
dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n");
return -EINVAL;
}
s->iosize != sizeof(uint32_t))
return dev_err_probe(&pdev->dev, -EINVAL,
"only 8/16/32-bit registers are supported\n");
iprop = of_get_property(np, "mux-mask", &len);
if (!iprop || len != sizeof(uint32_t)) {
dev_err(&pdev->dev, "missing or invalid mux-mask property\n");
return -ENODEV;
}
if (be32_to_cpup(iprop) >= BIT(s->iosize * 8)) {
dev_err(&pdev->dev, "only 8/16/32-bit registers are supported\n");
return -EINVAL;
}
if (!iprop || len != sizeof(uint32_t))
return dev_err_probe(&pdev->dev, -ENODEV,
"missing or invalid mux-mask property\n");
if (be32_to_cpup(iprop) >= BIT(s->iosize * 8))
return dev_err_probe(&pdev->dev, -EINVAL,
"only 8/16/32-bit registers are supported\n");
s->mask = be32_to_cpup(iprop);
/*
* Verify that the 'reg' property of each child MDIO bus does not
* 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;
if (of_property_read_reg(np2, 0, &reg, NULL)) {
dev_err(&pdev->dev, "mdio-mux child node %pOF is "
"missing a 'reg' property\n", np2);
of_node_put(np2);
return -ENODEV;
}
if ((u32)reg & ~s->mask) {
dev_err(&pdev->dev, "mdio-mux child node %pOF has "
"a 'reg' value with unmasked bits\n",
np2);
of_node_put(np2);
return -ENODEV;
}
if (of_property_read_reg(np2, 0, &reg, NULL))
return dev_err_probe(&pdev->dev, -ENODEV,
"mdio-mux child node %pOF is missing a 'reg' property\n",
np2);
if ((u32)reg & ~s->mask)
return dev_err_probe(&pdev->dev, -ENODEV,
"mdio-mux child node %pOF has a 'reg' value with unmasked bits\n",
np2);
}
ret = mdio_mux_init(&pdev->dev, pdev->dev.of_node,
......
......@@ -3407,7 +3407,7 @@ static int of_phy_led(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 *leds, *led;
struct device_node *leds;
int err;
if (!IS_ENABLED(CONFIG_OF_MDIO))
......@@ -3420,10 +3420,9 @@ static int of_phy_leds(struct phy_device *phydev)
if (!leds)
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);
if (err) {
of_node_put(led);
phy_leds_unregister(phydev);
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