linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/1] iio: adc: ad4170-4: Correctly update filter_fs after filter type change
@ 2025-07-20 15:37 Marcelo Schmitt
  2025-07-21  9:21 ` Nuno Sá
  2025-07-21 11:43 ` Andy Shevchenko
  0 siblings, 2 replies; 5+ messages in thread
From: Marcelo Schmitt @ 2025-07-20 15:37 UTC (permalink / raw)
  To: linux-iio, linux-kernel
  Cc: jic23, dan.carpenter, lars, Michael.Hennerich, dlechner, nuno.sa,
	andy, Markus.Elfring, marcelo.schmitt1

Previously, the driver was directly using the filter type value to update
the filter frequency (filter_fs) configuration. That caused the driver to
switch to the lowest filter_fs configuration (highest sampling frequency)
on every update to the filter type. Correct the filter_fs collateral update
by clamping it to the range of supported values instead of mistakenly
using the filter type to update the filter_fs.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/linux-iio/c6e54942-5b42-484b-be53-9d4606fd25c4@sabinyo.mountain/
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Fixes: 8ab7434734cd ("iio: adc: ad4170-4: Add digital filter and sample frequency config support")
Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
---
Hi, this is the same fix as the fix provided in implied v1 patch but with the
difference of doing it the way Markus suggested in reply to v1.
I have a slight preference for v1 since that one keeps code contained within
80 columns. Though, totally fine with whatever version of the fix gets picked up.

Change log v1 (implied) -> v2
- Replaces if by use of ternary operator as suggested by Markus in reply to v1.
- Fixed commit log typo: colateral -> collateral
- Fixed commit log typo: clampling -> clamping

Thanks,
Marcelo

 drivers/iio/adc/ad4170-4.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 6cd84d6fb08b..2e61f9a9a1ef 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -879,12 +879,11 @@ static int ad4170_set_filter_type(struct iio_dev *indio_dev,
 		if (!iio_device_claim_direct(indio_dev))
 			return -EBUSY;
 
-		if (val == AD4170_SINC5_AVG || val == AD4170_SINC3)
-			setup->filter_fs = clamp(val, AD4170_SINC3_MIN_FS,
-						 AD4170_SINC3_MAX_FS);
-		else
-			setup->filter_fs = clamp(val, AD4170_SINC5_MIN_FS,
-						 AD4170_SINC5_MAX_FS);
+		setup->filter_fs = (val == AD4170_SINC5_AVG || val == AD4170_SINC3)
+				    ? clamp(setup->filter_fs,
+					    AD4170_SINC3_MIN_FS, AD4170_SINC3_MAX_FS)
+				    : clamp(setup->filter_fs,
+					    AD4170_SINC5_MIN_FS, AD4170_SINC5_MAX_FS);
 
 		setup->filter &= ~AD4170_FILTER_FILTER_TYPE_MSK;
 		setup->filter |= FIELD_PREP(AD4170_FILTER_FILTER_TYPE_MSK,

base-commit: cd2731444ee4e35db76f4fb587f12d327eec5446
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] iio: adc: ad4170-4: Correctly update filter_fs after filter type change
  2025-07-20 15:37 [PATCH v2 1/1] iio: adc: ad4170-4: Correctly update filter_fs after filter type change Marcelo Schmitt
@ 2025-07-21  9:21 ` Nuno Sá
  2025-07-21 11:43 ` Andy Shevchenko
  1 sibling, 0 replies; 5+ messages in thread
From: Nuno Sá @ 2025-07-21  9:21 UTC (permalink / raw)
  To: Marcelo Schmitt
  Cc: linux-iio, linux-kernel, jic23, dan.carpenter, lars,
	Michael.Hennerich, dlechner, nuno.sa, andy, Markus.Elfring,
	marcelo.schmitt1

On Sun, Jul 20, 2025 at 12:37:24PM -0300, Marcelo Schmitt wrote:
> Previously, the driver was directly using the filter type value to update
> the filter frequency (filter_fs) configuration. That caused the driver to
> switch to the lowest filter_fs configuration (highest sampling frequency)
> on every update to the filter type. Correct the filter_fs collateral update
> by clamping it to the range of supported values instead of mistakenly
> using the filter type to update the filter_fs.
> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Link: https://lore.kernel.org/linux-iio/c6e54942-5b42-484b-be53-9d4606fd25c4@sabinyo.mountain/
> Suggested-by: Jonathan Cameron <jic23@kernel.org>
> Fixes: 8ab7434734cd ("iio: adc: ad4170-4: Add digital filter and sample frequency config support")
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
> ---
> Hi, this is the same fix as the fix provided in implied v1 patch but with the
> difference of doing it the way Markus suggested in reply to v1.
> I have a slight preference for v1 since that one keeps code contained within
> 80 columns. Though, totally fine with whatever version of the fix gets picked up.
> 
> Change log v1 (implied) -> v2
> - Replaces if by use of ternary operator as suggested by Markus in reply to v1.
> - Fixed commit log typo: colateral -> collateral
> - Fixed commit log typo: clampling -> clamping
> 
> Thanks,
> Marcelo
> 
>  drivers/iio/adc/ad4170-4.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
> index 6cd84d6fb08b..2e61f9a9a1ef 100644
> --- a/drivers/iio/adc/ad4170-4.c
> +++ b/drivers/iio/adc/ad4170-4.c
> @@ -879,12 +879,11 @@ static int ad4170_set_filter_type(struct iio_dev *indio_dev,
>  		if (!iio_device_claim_direct(indio_dev))
>  			return -EBUSY;
>  
> -		if (val == AD4170_SINC5_AVG || val == AD4170_SINC3)
> -			setup->filter_fs = clamp(val, AD4170_SINC3_MIN_FS,
> -						 AD4170_SINC3_MAX_FS);
> -		else
> -			setup->filter_fs = clamp(val, AD4170_SINC5_MIN_FS,
> -						 AD4170_SINC5_MAX_FS);
> +		setup->filter_fs = (val == AD4170_SINC5_AVG || val == AD4170_SINC3)
> +				    ? clamp(setup->filter_fs,
> +					    AD4170_SINC3_MIN_FS, AD4170_SINC3_MAX_FS)
> +				    : clamp(setup->filter_fs,
> +					    AD4170_SINC5_MIN_FS, AD4170_SINC5_MAX_FS);

I very much prefer the approach in v1. To me, this code is just harder
to read...

Reminder to why is a good idea to wait a bit and don't rush into
spinning new versions. Also, Markus has a very proven record of not
being helpful at all in reviews (just look in lore :))

With that:

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

- Nuno Sá

>  
>  		setup->filter &= ~AD4170_FILTER_FILTER_TYPE_MSK;
>  		setup->filter |= FIELD_PREP(AD4170_FILTER_FILTER_TYPE_MSK,
> 
> base-commit: cd2731444ee4e35db76f4fb587f12d327eec5446
> -- 
> 2.47.2
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] iio: adc: ad4170-4: Correctly update filter_fs after filter type change
  2025-07-20 15:37 [PATCH v2 1/1] iio: adc: ad4170-4: Correctly update filter_fs after filter type change Marcelo Schmitt
  2025-07-21  9:21 ` Nuno Sá
@ 2025-07-21 11:43 ` Andy Shevchenko
  2025-07-24 12:51   ` Jonathan Cameron
  1 sibling, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2025-07-21 11:43 UTC (permalink / raw)
  To: Marcelo Schmitt
  Cc: linux-iio, linux-kernel, jic23, dan.carpenter, lars,
	Michael.Hennerich, dlechner, nuno.sa, andy, Markus.Elfring,
	marcelo.schmitt1

On Sun, Jul 20, 2025 at 12:37:24PM -0300, Marcelo Schmitt wrote:
> Previously, the driver was directly using the filter type value to update
> the filter frequency (filter_fs) configuration. That caused the driver to
> switch to the lowest filter_fs configuration (highest sampling frequency)
> on every update to the filter type. Correct the filter_fs collateral update
> by clamping it to the range of supported values instead of mistakenly
> using the filter type to update the filter_fs.
> 
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Link: https://lore.kernel.org/linux-iio/c6e54942-5b42-484b-be53-9d4606fd25c4@sabinyo.mountain/

You mean Closes: here?

> Suggested-by: Jonathan Cameron <jic23@kernel.org>
> Fixes: 8ab7434734cd ("iio: adc: ad4170-4: Add digital filter and sample frequency config support")
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/1] iio: adc: ad4170-4: Correctly update filter_fs after filter type change
  2025-07-21 11:43 ` Andy Shevchenko
@ 2025-07-24 12:51   ` Jonathan Cameron
  2025-07-24 13:29     ` [PATCH v2] " Markus Elfring
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Cameron @ 2025-07-24 12:51 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Marcelo Schmitt, linux-iio, linux-kernel, dan.carpenter, lars,
	Michael.Hennerich, dlechner, nuno.sa, andy, Markus.Elfring,
	marcelo.schmitt1

On Mon, 21 Jul 2025 14:43:38 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Sun, Jul 20, 2025 at 12:37:24PM -0300, Marcelo Schmitt wrote:
> > Previously, the driver was directly using the filter type value to update
> > the filter frequency (filter_fs) configuration. That caused the driver to
> > switch to the lowest filter_fs configuration (highest sampling frequency)
> > on every update to the filter type. Correct the filter_fs collateral update
> > by clamping it to the range of supported values instead of mistakenly
> > using the filter type to update the filter_fs.
> > 
> > Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> > Link: https://lore.kernel.org/linux-iio/c6e54942-5b42-484b-be53-9d4606fd25c4@sabinyo.mountain/  
> 
> You mean Closes: here?
> 
> > Suggested-by: Jonathan Cameron <jic23@kernel.org>
> > Fixes: 8ab7434734cd ("iio: adc: ad4170-4: Add digital filter and sample frequency config support")
> > Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com>  
> 

I picked up v1 and made that a closes tag.  Links to email threads are fine
(there was a question in v1 on this).

Applied to the fixes-togreg-for-6.17 branch.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] iio: adc: ad4170-4: Correctly update filter_fs after filter type change
  2025-07-24 12:51   ` Jonathan Cameron
@ 2025-07-24 13:29     ` Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2025-07-24 13:29 UTC (permalink / raw)
  To: Jonathan Cameron, Andy Shevchenko, Marcelo Schmitt, linux-iio
  Cc: LKML, Andy Shevchenko, Dan Carpenter, David Lechner,
	Lars-Peter Clausen, Marcelo Schmitt, Michael Hennerich,
	Nuno Sá

>>> Previously, the driver was directly using the filter type value to update
>>> the filter frequency (filter_fs) configuration. That caused the driver to
>>> switch to the lowest filter_fs configuration (highest sampling frequency)
>>> on every update to the filter type. Correct the filter_fs collateral update
>>> by clamping it to the range of supported values instead of mistakenly
>>> using the filter type to update the filter_fs.
…> I picked up v1 and made that a closes tag.  Links to email threads are fine
> (there was a question in v1 on this).
> 
> Applied to the fixes-togreg-for-6.17 branch.

Would you like to avoid typos anyhow for the final commit message?
https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git/commit/?h=fixes-togreg-for-6.17&id=e4d9886ad25adae72f38f2b12f41649b101581ae

Regards,
Markus

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-07-24 13:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-20 15:37 [PATCH v2 1/1] iio: adc: ad4170-4: Correctly update filter_fs after filter type change Marcelo Schmitt
2025-07-21  9:21 ` Nuno Sá
2025-07-21 11:43 ` Andy Shevchenko
2025-07-24 12:51   ` Jonathan Cameron
2025-07-24 13:29     ` [PATCH v2] " Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).