diff mbox series

[3/4] iio: adc: sun20i-gpadc: use scoped device_for_each_child_node()

Message ID 20240926-iio_device_for_each_child_node_scoped-v1-3-64ca8a424578@gmail.com (mailing list archive)
State Not Applicable
Headers show
Series iio: adc: use scoped device_for_each_childe_node() | expand

Commit Message

Javier Carrasco Sept. 26, 2024, 4:08 p.m. UTC
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>
---
 drivers/iio/adc/sun20i-gpadc-iio.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Chen-Yu Tsai Sept. 26, 2024, 4:48 p.m. UTC | #1
On Fri, Sep 27, 2024 at 12:08 AM Javier Carrasco
<javier.carrasco.cruz@gmail.com> wrote:
>
> 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>

> ---
>  drivers/iio/adc/sun20i-gpadc-iio.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/adc/sun20i-gpadc-iio.c b/drivers/iio/adc/sun20i-gpadc-iio.c
> index 6a893d484cf7..136b8d9c294f 100644
> --- a/drivers/iio/adc/sun20i-gpadc-iio.c
> +++ b/drivers/iio/adc/sun20i-gpadc-iio.c
> @@ -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;
>
> --
> 2.43.0
>
diff mbox series

Patch

diff --git a/drivers/iio/adc/sun20i-gpadc-iio.c b/drivers/iio/adc/sun20i-gpadc-iio.c
index 6a893d484cf7..136b8d9c294f 100644
--- a/drivers/iio/adc/sun20i-gpadc-iio.c
+++ b/drivers/iio/adc/sun20i-gpadc-iio.c
@@ -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;