diff mbox series

iio: adc: ti-ads1015: use device_for_each_child_node_scoped()

Message ID 20240426131953.14933-1-lincolnyuji@usp.br (mailing list archive)
State Changes Requested
Headers show
Series iio: adc: ti-ads1015: use device_for_each_child_node_scoped() | expand

Commit Message

Lincoln Yuji April 26, 2024, 1:19 p.m. UTC
From: Lincoln Yuji <lincolnyuji@hotmail.com>

This loop definition removes the need for manual releasing of the fwnode_handle
in early exit paths (here an error path) allow simplification of the code
and reducing the chance of future modifications not releasing
fwnode_handle correctly.

Co-developed-by: Luiza Soezima <lbrsoezima@usp.br>
Signed-off-by: Luiza Soezima <lbrsoezima@usp.br>
Co-developed-by: Sabrina Araujo <sabrinaaraujo@usp.br>
Signed-off-by: Sabrina Araujo <sabrinaaraujo@usp.br>
Signed-off-by: Lincoln Yuji <lincolnyuji@usp.br>
---
 drivers/iio/adc/ti-ads1015.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Marcelo Schmitt April 27, 2024, 11:14 a.m. UTC | #1
Hi Lincoln, Sabrina, Luiza,

The patch looks good, though the message should be wrapped to 75 columns
and the "From:" tag was not needed and caused an email mismatch.

With those adjustments made,
Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>

Regards,
Marcelo

On 04/26, Lincoln Yuji wrote:
> From: Lincoln Yuji <lincolnyuji@hotmail.com>
> 
> This loop definition removes the need for manual releasing of the fwnode_handle
> in early exit paths (here an error path) allow simplification of the code
> and reducing the chance of future modifications not releasing
> fwnode_handle correctly.
> 
> Co-developed-by: Luiza Soezima <lbrsoezima@usp.br>
> Signed-off-by: Luiza Soezima <lbrsoezima@usp.br>
> Co-developed-by: Sabrina Araujo <sabrinaaraujo@usp.br>
> Signed-off-by: Sabrina Araujo <sabrinaaraujo@usp.br>
> Signed-off-by: Lincoln Yuji <lincolnyuji@usp.br>
> ---
>  drivers/iio/adc/ti-ads1015.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> index 6ae967e4d..d3363d02f 100644
> --- a/drivers/iio/adc/ti-ads1015.c
> +++ b/drivers/iio/adc/ti-ads1015.c
> @@ -902,10 +902,9 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
>  	struct iio_dev *indio_dev = i2c_get_clientdata(client);
>  	struct ads1015_data *data = iio_priv(indio_dev);
>  	struct device *dev = &client->dev;
> -	struct fwnode_handle *node;
>  	int i = -1;
>  
> -	device_for_each_child_node(dev, node) {
> +	device_for_each_child_node_scoped(dev, node) {
>  		u32 pval;
>  		unsigned int channel;
>  		unsigned int pga = ADS1015_DEFAULT_PGA;
> @@ -927,7 +926,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
>  			pga = pval;
>  			if (pga > 5) {
>  				dev_err(dev, "invalid gain on %pfw\n", node);
> -				fwnode_handle_put(node);
>  				return -EINVAL;
>  			}
>  		}
> @@ -936,7 +934,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
>  			data_rate = pval;
>  			if (data_rate > 7) {
>  				dev_err(dev, "invalid data_rate on %pfw\n", node);
> -				fwnode_handle_put(node);
>  				return -EINVAL;
>  			}
>  		}
> -- 
> 2.34.1
> 
>
Jonathan Cameron April 28, 2024, 3:36 p.m. UTC | #2
On Sat, 27 Apr 2024 08:14:50 -0300
Marcelo Schmitt <marcelo.schmitt1@gmail.com> wrote:

> Hi Lincoln, Sabrina, Luiza,
> 
> The patch looks good, though the message should be wrapped to 75 columns
> and the "From:" tag was not needed and caused an email mismatch.
That usually means the commit author in the git tree this was generated
from is incorrect. Set that to match your email with
git commit --amend --author="Lincoln Yuji <lincolnyuji@usp.br>"


> 
> With those adjustments made,
> Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
> 
> Regards,
> Marcelo
> 
> On 04/26, Lincoln Yuji wrote:
> > From: Lincoln Yuji <lincolnyuji@hotmail.com>
> > 
> > This loop definition removes the need for manual releasing of the fwnode_handle
> > in early exit paths (here an error path) allow simplification of the code
> > and reducing the chance of future modifications not releasing
> > fwnode_handle correctly.
> > 
> > Co-developed-by: Luiza Soezima <lbrsoezima@usp.br>
> > Signed-off-by: Luiza Soezima <lbrsoezima@usp.br>
> > Co-developed-by: Sabrina Araujo <sabrinaaraujo@usp.br>
> > Signed-off-by: Sabrina Araujo <sabrinaaraujo@usp.br>
> > Signed-off-by: Lincoln Yuji <lincolnyuji@usp.br>
> > ---
> >  drivers/iio/adc/ti-ads1015.c | 5 +----
> >  1 file changed, 1 insertion(+), 4 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> > index 6ae967e4d..d3363d02f 100644
> > --- a/drivers/iio/adc/ti-ads1015.c
> > +++ b/drivers/iio/adc/ti-ads1015.c
> > @@ -902,10 +902,9 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
> >  	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> >  	struct ads1015_data *data = iio_priv(indio_dev);
> >  	struct device *dev = &client->dev;
> > -	struct fwnode_handle *node;
> >  	int i = -1;
> >  
> > -	device_for_each_child_node(dev, node) {
> > +	device_for_each_child_node_scoped(dev, node) {
> >  		u32 pval;
> >  		unsigned int channel;
> >  		unsigned int pga = ADS1015_DEFAULT_PGA;
> > @@ -927,7 +926,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
> >  			pga = pval;
> >  			if (pga > 5) {
> >  				dev_err(dev, "invalid gain on %pfw\n", node);
> > -				fwnode_handle_put(node);
> >  				return -EINVAL;
> >  			}
> >  		}
> > @@ -936,7 +934,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
> >  			data_rate = pval;
> >  			if (data_rate > 7) {
> >  				dev_err(dev, "invalid data_rate on %pfw\n", node);
> > -				fwnode_handle_put(node);
> >  				return -EINVAL;
> >  			}
> >  		}
> > -- 
> > 2.34.1
> > 
> >
Jonathan Cameron April 28, 2024, 3:41 p.m. UTC | #3
On Sun, 28 Apr 2024 16:36:52 +0100
Jonathan Cameron <jic23@kernel.org> wrote:

> On Sat, 27 Apr 2024 08:14:50 -0300
> Marcelo Schmitt <marcelo.schmitt1@gmail.com> wrote:
> 
> > Hi Lincoln, Sabrina, Luiza,
> > 
> > The patch looks good, though the message should be wrapped to 75 columns
> > and the "From:" tag was not needed and caused an email mismatch.  
> That usually means the commit author in the git tree this was generated
> from is incorrect. Set that to match your email with
> git commit --amend --author="Lincoln Yuji <lincolnyuji@usp.br>"
> 
Nope. I was wrong on that.   Indeed what Marcelo said in another
thread, you need to set the --from

Jonathan

> 
> > 
> > With those adjustments made,
> > Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
> > 
> > Regards,
> > Marcelo
> > 
> > On 04/26, Lincoln Yuji wrote:  
> > > From: Lincoln Yuji <lincolnyuji@hotmail.com>
> > > 
> > > This loop definition removes the need for manual releasing of the fwnode_handle
> > > in early exit paths (here an error path) allow simplification of the code
> > > and reducing the chance of future modifications not releasing
> > > fwnode_handle correctly.
> > > 
> > > Co-developed-by: Luiza Soezima <lbrsoezima@usp.br>
> > > Signed-off-by: Luiza Soezima <lbrsoezima@usp.br>
> > > Co-developed-by: Sabrina Araujo <sabrinaaraujo@usp.br>
> > > Signed-off-by: Sabrina Araujo <sabrinaaraujo@usp.br>
> > > Signed-off-by: Lincoln Yuji <lincolnyuji@usp.br>
> > > ---
> > >  drivers/iio/adc/ti-ads1015.c | 5 +----
> > >  1 file changed, 1 insertion(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
> > > index 6ae967e4d..d3363d02f 100644
> > > --- a/drivers/iio/adc/ti-ads1015.c
> > > +++ b/drivers/iio/adc/ti-ads1015.c
> > > @@ -902,10 +902,9 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
> > >  	struct iio_dev *indio_dev = i2c_get_clientdata(client);
> > >  	struct ads1015_data *data = iio_priv(indio_dev);
> > >  	struct device *dev = &client->dev;
> > > -	struct fwnode_handle *node;
> > >  	int i = -1;
> > >  
> > > -	device_for_each_child_node(dev, node) {
> > > +	device_for_each_child_node_scoped(dev, node) {
> > >  		u32 pval;
> > >  		unsigned int channel;
> > >  		unsigned int pga = ADS1015_DEFAULT_PGA;
> > > @@ -927,7 +926,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
> > >  			pga = pval;
> > >  			if (pga > 5) {
> > >  				dev_err(dev, "invalid gain on %pfw\n", node);
> > > -				fwnode_handle_put(node);
> > >  				return -EINVAL;
> > >  			}
> > >  		}
> > > @@ -936,7 +934,6 @@ static int ads1015_client_get_channels_config(struct i2c_client *client)
> > >  			data_rate = pval;
> > >  			if (data_rate > 7) {
> > >  				dev_err(dev, "invalid data_rate on %pfw\n", node);
> > > -				fwnode_handle_put(node);
> > >  				return -EINVAL;
> > >  			}
> > >  		}
> > > -- 
> > > 2.34.1
> > > 
> > >     
>
diff mbox series

Patch

diff --git a/drivers/iio/adc/ti-ads1015.c b/drivers/iio/adc/ti-ads1015.c
index 6ae967e4d..d3363d02f 100644
--- a/drivers/iio/adc/ti-ads1015.c
+++ b/drivers/iio/adc/ti-ads1015.c
@@ -902,10 +902,9 @@  static int ads1015_client_get_channels_config(struct i2c_client *client)
 	struct iio_dev *indio_dev = i2c_get_clientdata(client);
 	struct ads1015_data *data = iio_priv(indio_dev);
 	struct device *dev = &client->dev;
-	struct fwnode_handle *node;
 	int i = -1;
 
-	device_for_each_child_node(dev, node) {
+	device_for_each_child_node_scoped(dev, node) {
 		u32 pval;
 		unsigned int channel;
 		unsigned int pga = ADS1015_DEFAULT_PGA;
@@ -927,7 +926,6 @@  static int ads1015_client_get_channels_config(struct i2c_client *client)
 			pga = pval;
 			if (pga > 5) {
 				dev_err(dev, "invalid gain on %pfw\n", node);
-				fwnode_handle_put(node);
 				return -EINVAL;
 			}
 		}
@@ -936,7 +934,6 @@  static int ads1015_client_get_channels_config(struct i2c_client *client)
 			data_rate = pval;
 			if (data_rate > 7) {
 				dev_err(dev, "invalid data_rate on %pfw\n", node);
-				fwnode_handle_put(node);
 				return -EINVAL;
 			}
 		}