diff mbox series

[v6,8/8] iio: dac: ad5770r: Use device_for_each_child_node_scoped()

Message ID 20240330185305.1319844-9-jic23@kernel.org (mailing list archive)
State Accepted
Headers show
Series IIO: Use device_for_each_child_scope() | expand

Commit Message

Jonathan Cameron March 30, 2024, 6:53 p.m. UTC
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Switching to the _scoped() version removes the need for manual
calling of fwnode_handle_put() in the paths where the code
exits the loop early. In this case that's all in error paths.

Cc: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/dac/ad5770r.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

Comments

Nuno Sá April 4, 2024, 9:11 a.m. UTC | #1
On Sat, 2024-03-30 at 18:53 +0000, Jonathan Cameron wrote:
> From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> 
> Switching to the _scoped() version removes the need for manual
> calling of fwnode_handle_put() in the paths where the code
> exits the loop early. In this case that's all in error paths.
> 
> Cc: Nuno Sá <nuno.sa@analog.com>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---

Reviewed-by: Nuno Sa <nuno.sa@analog.com>

>  drivers/iio/dac/ad5770r.c | 19 ++++++-------------
>  1 file changed, 6 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iio/dac/ad5770r.c b/drivers/iio/dac/ad5770r.c
> index f66d67402e43..c360ebf5297a 100644
> --- a/drivers/iio/dac/ad5770r.c
> +++ b/drivers/iio/dac/ad5770r.c
> @@ -515,39 +515,32 @@ static int ad5770r_channel_config(struct ad5770r_state
> *st)
>  {
>  	int ret, tmp[2], min, max;
>  	unsigned int num;
> -	struct fwnode_handle *child;
>  
>  	num = device_get_child_node_count(&st->spi->dev);
>  	if (num != AD5770R_MAX_CHANNELS)
>  		return -EINVAL;
>  
> -	device_for_each_child_node(&st->spi->dev, child) {
> +	device_for_each_child_node_scoped(&st->spi->dev, child) {
>  		ret = fwnode_property_read_u32(child, "reg", &num);
>  		if (ret)
> -			goto err_child_out;
> -		if (num >= AD5770R_MAX_CHANNELS) {
> -			ret = -EINVAL;
> -			goto err_child_out;
> -		}
> +			return ret;
> +		if (num >= AD5770R_MAX_CHANNELS)
> +			return -EINVAL;
>  
>  		ret = fwnode_property_read_u32_array(child,
>  						     "adi,range-microamp",
>  						     tmp, 2);
>  		if (ret)
> -			goto err_child_out;
> +			return ret;
>  
>  		min = tmp[0] / 1000;
>  		max = tmp[1] / 1000;
>  		ret = ad5770r_store_output_range(st, min, max, num);
>  		if (ret)
> -			goto err_child_out;
> +			return ret;
>  	}
>  
>  	return 0;
> -
> -err_child_out:
> -	fwnode_handle_put(child);
> -	return ret;
>  }
>  
>  static int ad5770r_init(struct ad5770r_state *st)
Jonathan Cameron April 6, 2024, 10:19 a.m. UTC | #2
On Thu, 04 Apr 2024 11:11:11 +0200
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Sat, 2024-03-30 at 18:53 +0000, Jonathan Cameron wrote:
> > From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > 
> > Switching to the _scoped() version removes the need for manual
> > calling of fwnode_handle_put() in the paths where the code
> > exits the loop early. In this case that's all in error paths.
> > 
> > Cc: Nuno Sá <nuno.sa@analog.com>
> > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> > ---  
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
> 
Applied.
diff mbox series

Patch

diff --git a/drivers/iio/dac/ad5770r.c b/drivers/iio/dac/ad5770r.c
index f66d67402e43..c360ebf5297a 100644
--- a/drivers/iio/dac/ad5770r.c
+++ b/drivers/iio/dac/ad5770r.c
@@ -515,39 +515,32 @@  static int ad5770r_channel_config(struct ad5770r_state *st)
 {
 	int ret, tmp[2], min, max;
 	unsigned int num;
-	struct fwnode_handle *child;
 
 	num = device_get_child_node_count(&st->spi->dev);
 	if (num != AD5770R_MAX_CHANNELS)
 		return -EINVAL;
 
-	device_for_each_child_node(&st->spi->dev, child) {
+	device_for_each_child_node_scoped(&st->spi->dev, child) {
 		ret = fwnode_property_read_u32(child, "reg", &num);
 		if (ret)
-			goto err_child_out;
-		if (num >= AD5770R_MAX_CHANNELS) {
-			ret = -EINVAL;
-			goto err_child_out;
-		}
+			return ret;
+		if (num >= AD5770R_MAX_CHANNELS)
+			return -EINVAL;
 
 		ret = fwnode_property_read_u32_array(child,
 						     "adi,range-microamp",
 						     tmp, 2);
 		if (ret)
-			goto err_child_out;
+			return ret;
 
 		min = tmp[0] / 1000;
 		max = tmp[1] / 1000;
 		ret = ad5770r_store_output_range(st, min, max, num);
 		if (ret)
-			goto err_child_out;
+			return ret;
 	}
 
 	return 0;
-
-err_child_out:
-	fwnode_handle_put(child);
-	return ret;
 }
 
 static int ad5770r_init(struct ad5770r_state *st)