]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
iio: adc: sun20i-gpadc: use scoped device_for_each_child_node()
authorJavier Carrasco <javier.carrasco.cruz@gmail.com>
Thu, 26 Sep 2024 16:08:39 +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>
Reviewed-by: Chen-Yu Tsai <wens@csie.org>
Link: https://patch.msgid.link/20240926-iio_device_for_each_child_node_scoped-v1-3-64ca8a424578@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/sun20i-gpadc-iio.c

index 6a893d484cf7038f306eca6851beff4c84740864..136b8d9c294f4679adf813316eae19c2926a2742 100644 (file)
@@ -155,7 +155,6 @@ static int sun20i_gpadc_alloc_channels(struct iio_dev *indio_dev,
        unsigned int channel;
        int num_channels, i, ret;
        struct iio_chan_spec *channels;
-       struct fwnode_handle *node;
 
        num_channels = device_get_child_node_count(dev);
        if (num_channels == 0)
@@ -167,12 +166,10 @@ static int sun20i_gpadc_alloc_channels(struct iio_dev *indio_dev,
                return -ENOMEM;
 
        i = 0;
-       device_for_each_child_node(dev, node) {
+       device_for_each_child_node_scoped(dev, node) {
                ret = fwnode_property_read_u32(node, "reg", &channel);
-               if (ret) {
-                       fwnode_handle_put(node);
+               if (ret)
                        return dev_err_probe(dev, ret, "invalid channel number\n");
-               }
 
                channels[i].type = IIO_VOLTAGE;
                channels[i].indexed = 1;