]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
iio: adc: qcom-spmi-vadc: use scoped device_for_each_child_node()
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Thu, 26 Sep 2024 16:08:38 +0000 (18:08 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 5 Oct 2024 11:09:14 +0000 (12:09 +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 path.

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

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Link: https://patch.msgid.link/20240926-iio_device_for_each_child_node_scoped-v1-2-64ca8a424578@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/qcom-spmi-vadc.c

index f5c6f1f27b2c7de16326c0465f6c3c7899abb746..00a7f098202543891d7ae6c0ab2904b78b96b8fb 100644 (file)
@@ -754,7 +754,6 @@ static int vadc_get_fw_data(struct vadc_priv *vadc)
        const struct vadc_channels *vadc_chan;
        struct iio_chan_spec *iio_chan;
        struct vadc_channel_prop prop;
-       struct fwnode_handle *child;
        unsigned int index = 0;
        int ret;
 
@@ -774,12 +773,10 @@ static int vadc_get_fw_data(struct vadc_priv *vadc)
 
        iio_chan = vadc->iio_chans;
 
-       device_for_each_child_node(vadc->dev, child) {
+       device_for_each_child_node_scoped(vadc->dev, child) {
                ret = vadc_get_fw_channel_data(vadc->dev, &prop, child);
-               if (ret) {
-                       fwnode_handle_put(child);
+               if (ret)
                        return ret;
-               }
 
                prop.scale_fn_type = vadc_chans[prop.channel].scale_fn_type;
                vadc->chan_props[index] = prop;