diff mbox series

iio: adc: ad7124: fix DT configuration parsing

Message ID 20240806085133.114547-1-dumitru.ceclan@analog.com (mailing list archive)
State Accepted
Headers show
Series iio: adc: ad7124: fix DT configuration parsing | expand

Commit Message

Ceclan, Dumitru Aug. 6, 2024, 8:51 a.m. UTC
The cfg pointer is set before reading the channel number that the
configuration should point to. This causes configurations to be shifted
by one channel.
For example setting bipolar to the first channel defined in the DT will
cause bipolar mode to be active on the second defined channel.

Fix by moving the cfg pointer setting after reading the channel number.

Fixes: 7b8d045e497a ("iio: adc: ad7124: allow more than 8 channels")
Signed-off-by: Dumitru Ceclan <dumitru.ceclan@analog.com>
---
 drivers/iio/adc/ad7124.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Nuno Sá Aug. 6, 2024, 10:45 a.m. UTC | #1
On Tue, 2024-08-06 at 11:51 +0300, Dumitru Ceclan wrote:
> The cfg pointer is set before reading the channel number that the
> configuration should point to. This causes configurations to be shifted
> by one channel.
> For example setting bipolar to the first channel defined in the DT will
> cause bipolar mode to be active on the second defined channel.
> 
> Fix by moving the cfg pointer setting after reading the channel number.
> 
> Fixes: 7b8d045e497a ("iio: adc: ad7124: allow more than 8 channels")
> Signed-off-by: Dumitru Ceclan <dumitru.ceclan@analog.com>
> ---

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

>  drivers/iio/adc/ad7124.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> index 3beed78496c5..672d41bac8ca 100644
> --- a/drivers/iio/adc/ad7124.c
> +++ b/drivers/iio/adc/ad7124.c
> @@ -839,8 +839,6 @@ static int ad7124_parse_channel_config(struct iio_dev
> *indio_dev,
>  	st->channels = channels;
>  
>  	device_for_each_child_node_scoped(dev, child) {
> -		cfg = &st->channels[channel].cfg;
> -
>  		ret = fwnode_property_read_u32(child, "reg", &channel);
>  		if (ret)
>  			return ret;
> @@ -858,6 +856,7 @@ static int ad7124_parse_channel_config(struct iio_dev
> *indio_dev,
>  		st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
>  						  AD7124_CHANNEL_AINM(ain[1]);
>  
> +		cfg = &st->channels[channel].cfg;
>  		cfg->bipolar = fwnode_property_read_bool(child, "bipolar");
>  
>  		ret = fwnode_property_read_u32(child, "adi,reference-select",
> &tmp);
Jonathan Cameron Aug. 6, 2024, 4:04 p.m. UTC | #2
On Tue, 06 Aug 2024 12:45:06 +0200
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Tue, 2024-08-06 at 11:51 +0300, Dumitru Ceclan wrote:
> > The cfg pointer is set before reading the channel number that the
> > configuration should point to. This causes configurations to be shifted
> > by one channel.
> > For example setting bipolar to the first channel defined in the DT will
> > cause bipolar mode to be active on the second defined channel.
> > 
> > Fix by moving the cfg pointer setting after reading the channel number.
> > 
> > Fixes: 7b8d045e497a ("iio: adc: ad7124: allow more than 8 channels")
> > Signed-off-by: Dumitru Ceclan <dumitru.ceclan@analog.com>
> > ---  
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>
Applied to the fixes-togreg branch of iio.git and marked for stable.

Thanks,

Jonathan

> 
> >  drivers/iio/adc/ad7124.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
> > index 3beed78496c5..672d41bac8ca 100644
> > --- a/drivers/iio/adc/ad7124.c
> > +++ b/drivers/iio/adc/ad7124.c
> > @@ -839,8 +839,6 @@ static int ad7124_parse_channel_config(struct iio_dev
> > *indio_dev,
> >  	st->channels = channels;
> >  
> >  	device_for_each_child_node_scoped(dev, child) {
> > -		cfg = &st->channels[channel].cfg;
> > -
> >  		ret = fwnode_property_read_u32(child, "reg", &channel);
> >  		if (ret)
> >  			return ret;
> > @@ -858,6 +856,7 @@ static int ad7124_parse_channel_config(struct iio_dev
> > *indio_dev,
> >  		st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
> >  						  AD7124_CHANNEL_AINM(ain[1]);
> >  
> > +		cfg = &st->channels[channel].cfg;
> >  		cfg->bipolar = fwnode_property_read_bool(child, "bipolar");
> >  
> >  		ret = fwnode_property_read_u32(child, "adi,reference-select",
> > &tmp);  
> 
>
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad7124.c b/drivers/iio/adc/ad7124.c
index 3beed78496c5..672d41bac8ca 100644
--- a/drivers/iio/adc/ad7124.c
+++ b/drivers/iio/adc/ad7124.c
@@ -839,8 +839,6 @@  static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
 	st->channels = channels;
 
 	device_for_each_child_node_scoped(dev, child) {
-		cfg = &st->channels[channel].cfg;
-
 		ret = fwnode_property_read_u32(child, "reg", &channel);
 		if (ret)
 			return ret;
@@ -858,6 +856,7 @@  static int ad7124_parse_channel_config(struct iio_dev *indio_dev,
 		st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |
 						  AD7124_CHANNEL_AINM(ain[1]);
 
+		cfg = &st->channels[channel].cfg;
 		cfg->bipolar = fwnode_property_read_bool(child, "bipolar");
 
 		ret = fwnode_property_read_u32(child, "adi,reference-select", &tmp);