net: mdio: mux-mmioreg: Simplified with scoped function
authorJinjie Ruan <ruanjinjie@huawei.com>
Fri, 30 Aug 2024 03:13:21 +0000 (11:13 +0800)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 3 Sep 2024 10:54:43 +0000 (12:54 +0200)
Avoids the need for manual cleanup of_node_put() in early exits
from the loop by using for_each_available_child_of_node_scoped().

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/mdio/mdio-mux-mmioreg.c

index de08419d0c9852b6917f1ac7dce41e2241bc882e..4d87e61fec7bc444d1c9d068d2ee1f0196fe9238 100644 (file)
@@ -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;
@@ -139,20 +139,18 @@ static int mdio_mux_mmioreg_probe(struct platform_device *pdev)
         * 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;
                }
        }