]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
leds: lm3697: Switch to device_for_each_child_node_scoped()
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Thu, 26 Sep 2024 23:21:00 +0000 (01:21 +0200)
committerLee Jones <lee@kernel.org>
Wed, 9 Oct 2024 14:17:27 +0000 (15:17 +0100)
Switch to device_for_each_child_node_scoped() to simplify the code by
removing the need for calls to fwnode_handle_put() in the error paths.

This also prevents possible memory leaks if new error paths are added
without the required call to fwnode_handle_put().

After switching to the scoped variant, there is no longer need for a
jump to 'child_out', as an immediate return is possible.

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://lore.kernel.org/r/20240927-leds_device_for_each_child_node_scoped-v1-9-95c0614b38c8@gmail.com
Signed-off-by: Lee Jones <lee@kernel.org>
drivers/leds/leds-lm3697.c

index 99de2a3317271a338995489eb5a1f55cf96487df..7ad232780a31006ac1a96e813e7d00fbe1727f84 100644 (file)
@@ -202,7 +202,6 @@ out:
 
 static int lm3697_probe_dt(struct lm3697 *priv)
 {
-       struct fwnode_handle *child = NULL;
        struct device *dev = priv->dev;
        struct lm3697_led *led;
        int ret = -EINVAL;
@@ -220,19 +219,18 @@ static int lm3697_probe_dt(struct lm3697 *priv)
        if (IS_ERR(priv->regulator))
                priv->regulator = NULL;
 
-       device_for_each_child_node(dev, child) {
+       device_for_each_child_node_scoped(dev, child) {
                struct led_init_data init_data = {};
 
                ret = fwnode_property_read_u32(child, "reg", &control_bank);
                if (ret) {
                        dev_err(dev, "reg property missing\n");
-                       goto child_out;
+                       return ret;
                }
 
                if (control_bank > LM3697_CONTROL_B) {
                        dev_err(dev, "reg property is invalid\n");
-                       ret = -EINVAL;
-                       goto child_out;
+                       return -EINVAL;
                }
 
                led = &priv->leds[i];
@@ -262,7 +260,7 @@ static int lm3697_probe_dt(struct lm3697 *priv)
                                                    led->num_leds);
                if (ret) {
                        dev_err(dev, "led-sources property missing\n");
-                       goto child_out;
+                       return ret;
                }
 
                for (j = 0; j < led->num_leds; j++)
@@ -286,17 +284,13 @@ static int lm3697_probe_dt(struct lm3697 *priv)
                                                     &init_data);
                if (ret) {
                        dev_err(dev, "led register err: %d\n", ret);
-                       goto child_out;
+                       return ret;
                }
 
                i++;
        }
 
-       return ret;
-
-child_out:
-       fwnode_handle_put(child);
-       return ret;
+       return 0;
 }
 
 static int lm3697_probe(struct i2c_client *client)