linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: dac: adi-axi: fix a mistake in axi_dac_ext_info_set()
@ 2024-04-24 11:45 Dan Carpenter
  2024-04-24 12:30 ` Nuno Sá
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2024-04-24 11:45 UTC (permalink / raw)
  To: Nuno Sa
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	linux-iio, linux-kernel, kernel-janitors

The last parameter of these axi_dac_(frequency|scale|phase)_set()
functions is supposed to be true for TONE_2 and false for TONE_1. The
bug is the last call where it passes "private - TONE_2".  That
subtraction is going to be zero/false for TONE_2 and and -1/true for
TONE_1.  Fix the bug, and re-write it as "private == TONE_2" so it's
more obvious what is happening.

Fixes: 4e3949a192e4 ("iio: dac: add support for AXI DAC IP core")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
This is from code review.  Untested.
---
 drivers/iio/dac/adi-axi-dac.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
index 9047c5aec0ff..880d83a014a1 100644
--- a/drivers/iio/dac/adi-axi-dac.c
+++ b/drivers/iio/dac/adi-axi-dac.c
@@ -383,15 +383,15 @@ static int axi_dac_ext_info_set(struct iio_backend *back, uintptr_t private,
 	case AXI_DAC_FREQ_TONE_1:
 	case AXI_DAC_FREQ_TONE_2:
 		return axi_dac_frequency_set(st, chan, buf, len,
-					     private - AXI_DAC_FREQ_TONE_1);
+					     private == AXI_DAC_FREQ_TONE_2);
 	case AXI_DAC_SCALE_TONE_1:
 	case AXI_DAC_SCALE_TONE_2:
 		return axi_dac_scale_set(st, chan, buf, len,
-					 private - AXI_DAC_SCALE_TONE_1);
+					 private == AXI_DAC_SCALE_TONE_2);
 	case AXI_DAC_PHASE_TONE_1:
 	case AXI_DAC_PHASE_TONE_2:
 		return axi_dac_phase_set(st, chan, buf, len,
-					 private - AXI_DAC_PHASE_TONE_2);
+					 private == AXI_DAC_PHASE_TONE_2);
 	default:
 		return -EOPNOTSUPP;
 	}
-- 
2.43.0


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

* Re: [PATCH] iio: dac: adi-axi: fix a mistake in axi_dac_ext_info_set()
  2024-04-24 11:45 [PATCH] iio: dac: adi-axi: fix a mistake in axi_dac_ext_info_set() Dan Carpenter
@ 2024-04-24 12:30 ` Nuno Sá
  2024-04-28 16:06   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Nuno Sá @ 2024-04-24 12:30 UTC (permalink / raw)
  To: Dan Carpenter, Nuno Sa
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	linux-iio, linux-kernel, kernel-janitors

Hi Dan,

On Wed, 2024-04-24 at 14:45 +0300, Dan Carpenter wrote:
> The last parameter of these axi_dac_(frequency|scale|phase)_set()
> functions is supposed to be true for TONE_2 and false for TONE_1. The
> bug is the last call where it passes "private - TONE_2".  That
> subtraction is going to be zero/false for TONE_2 and and -1/true for
> TONE_1.  Fix the bug, and re-write it as "private == TONE_2" so it's
> more obvious what is happening.
> 
> Fixes: 4e3949a192e4 ("iio: dac: add support for AXI DAC IP core")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> This is from code review.  Untested.
> ---

Auch, good catch! Agreed that private == AXI_DAC_*_TONE_2 makes it more
readable.

I guess Jonathan may just squash this in the driver (was pushed this weekend).
Anyways, FWIW:

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

>  drivers/iio/dac/adi-axi-dac.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
> index 9047c5aec0ff..880d83a014a1 100644
> --- a/drivers/iio/dac/adi-axi-dac.c
> +++ b/drivers/iio/dac/adi-axi-dac.c
> @@ -383,15 +383,15 @@ static int axi_dac_ext_info_set(struct iio_backend
> *back, uintptr_t private,
>  	case AXI_DAC_FREQ_TONE_1:
>  	case AXI_DAC_FREQ_TONE_2:
>  		return axi_dac_frequency_set(st, chan, buf, len,
> -					     private - AXI_DAC_FREQ_TONE_1);
> +					     private == AXI_DAC_FREQ_TONE_2);
>  	case AXI_DAC_SCALE_TONE_1:
>  	case AXI_DAC_SCALE_TONE_2:
>  		return axi_dac_scale_set(st, chan, buf, len,
> -					 private - AXI_DAC_SCALE_TONE_1);
> +					 private == AXI_DAC_SCALE_TONE_2);
>  	case AXI_DAC_PHASE_TONE_1:
>  	case AXI_DAC_PHASE_TONE_2:
>  		return axi_dac_phase_set(st, chan, buf, len,
> -					 private - AXI_DAC_PHASE_TONE_2);
> +					 private == AXI_DAC_PHASE_TONE_2);
>  	default:
>  		return -EOPNOTSUPP;
>  	}


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

* Re: [PATCH] iio: dac: adi-axi: fix a mistake in axi_dac_ext_info_set()
  2024-04-24 12:30 ` Nuno Sá
@ 2024-04-28 16:06   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2024-04-28 16:06 UTC (permalink / raw)
  To: Nuno Sá
  Cc: Dan Carpenter, Nuno Sa, Lars-Peter Clausen, Michael Hennerich,
	linux-iio, linux-kernel, kernel-janitors

On Wed, 24 Apr 2024 14:30:02 +0200
Nuno Sá <noname.nuno@gmail.com> wrote:

> Hi Dan,
> 
> On Wed, 2024-04-24 at 14:45 +0300, Dan Carpenter wrote:
> > The last parameter of these axi_dac_(frequency|scale|phase)_set()
> > functions is supposed to be true for TONE_2 and false for TONE_1. The
> > bug is the last call where it passes "private - TONE_2".  That
> > subtraction is going to be zero/false for TONE_2 and and -1/true for
> > TONE_1.  Fix the bug, and re-write it as "private == TONE_2" so it's
> > more obvious what is happening.
> > 
> > Fixes: 4e3949a192e4 ("iio: dac: add support for AXI DAC IP core")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> > This is from code review.  Untested.
> > ---  
> 
> Auch, good catch! Agreed that private == AXI_DAC_*_TONE_2 makes it more
> readable.
> 
> I guess Jonathan may just squash this in the driver (was pushed this weekend).
> Anyways, FWIW:
> 
> Reviewed-by: Nuno Sa <nuno.sa@analog.com>

Missed the pull request, so will have to follow it in next pull.

Applied to the togreg branch of iio.git and pushed out as testing. Thanks,

Jonathan

> 
> >  drivers/iio/dac/adi-axi-dac.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/iio/dac/adi-axi-dac.c b/drivers/iio/dac/adi-axi-dac.c
> > index 9047c5aec0ff..880d83a014a1 100644
> > --- a/drivers/iio/dac/adi-axi-dac.c
> > +++ b/drivers/iio/dac/adi-axi-dac.c
> > @@ -383,15 +383,15 @@ static int axi_dac_ext_info_set(struct iio_backend
> > *back, uintptr_t private,
> >  	case AXI_DAC_FREQ_TONE_1:
> >  	case AXI_DAC_FREQ_TONE_2:
> >  		return axi_dac_frequency_set(st, chan, buf, len,
> > -					     private - AXI_DAC_FREQ_TONE_1);
> > +					     private == AXI_DAC_FREQ_TONE_2);
> >  	case AXI_DAC_SCALE_TONE_1:
> >  	case AXI_DAC_SCALE_TONE_2:
> >  		return axi_dac_scale_set(st, chan, buf, len,
> > -					 private - AXI_DAC_SCALE_TONE_1);
> > +					 private == AXI_DAC_SCALE_TONE_2);
> >  	case AXI_DAC_PHASE_TONE_1:
> >  	case AXI_DAC_PHASE_TONE_2:
> >  		return axi_dac_phase_set(st, chan, buf, len,
> > -					 private - AXI_DAC_PHASE_TONE_2);
> > +					 private == AXI_DAC_PHASE_TONE_2);
> >  	default:
> >  		return -EOPNOTSUPP;
> >  	}  
> 


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

end of thread, other threads:[~2024-04-28 16:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-24 11:45 [PATCH] iio: dac: adi-axi: fix a mistake in axi_dac_ext_info_set() Dan Carpenter
2024-04-24 12:30 ` Nuno Sá
2024-04-28 16:06   ` Jonathan Cameron

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).