mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio:ad7793: Fix the serial interface reset
@ 2017-09-04 15:00 Dragos Bogdan
  2017-09-04 15:26 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Dragos Bogdan @ 2017-09-04 15:00 UTC (permalink / raw)
  To: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron
  Cc: Hartmut Knaack, Peter Meerwald-Stadler, linux-iio, linux-kernel,
	Dragos Bogdan

The serial interface can be reset by writing 32 consecutive 1s to the device.
The value of 'ret' is overwritten when ad7793_check_platform_data() is called,
so it should be initialized to -1 only before doing the spi_write().

Fixes: commit 2edb769d246e ("iio:ad7793: Add support for the ad7798 and ad7799")

Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
---
 drivers/iio/adc/ad7793.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
index e6706a09e100..8680abf72dd2 100644
--- a/drivers/iio/adc/ad7793.c
+++ b/drivers/iio/adc/ad7793.c
@@ -257,7 +257,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
 	unsigned int vref_mv)
 {
 	struct ad7793_state *st = iio_priv(indio_dev);
-	int i, ret = -1;
+	int i, ret;
 	unsigned long long scale_uv;
 	u32 id;
 
@@ -266,6 +266,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
 		return ret;
 
 	/* reset the serial interface */
+	ret = -1;
 	ret = spi_write(st->sd.spi, (u8 *)&ret, sizeof(ret));
 	if (ret < 0)
 		goto out;
-- 
2.11.0

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

* Re: [PATCH] iio:ad7793: Fix the serial interface reset
  2017-09-04 15:00 [PATCH] iio:ad7793: Fix the serial interface reset Dragos Bogdan
@ 2017-09-04 15:26 ` Jonathan Cameron
  2017-09-04 15:33   ` Bogdan, Dragos
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2017-09-04 15:26 UTC (permalink / raw)
  To: Dragos Bogdan
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, linux-iio, linux-kernel

On Mon, 4 Sep 2017 18:00:48 +0300
Dragos Bogdan <dragos.bogdan@analog.com> wrote:

> The serial interface can be reset by writing 32 consecutive 1s to the device.
> The value of 'ret' is overwritten when ad7793_check_platform_data() is called,
> so it should be initialized to -1 only before doing the spi_write().
> 
> Fixes: commit 2edb769d246e ("iio:ad7793: Add support for the ad7798 and ad7799")
> 
> Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>

Hi Dragos,

I'd prefer we introduced a separate variable.  Using ret for this
is what got us into trouble in the first place.

Would you mind respining with that change?

Thanks,

Jonathan

> ---
>  drivers/iio/adc/ad7793.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
> index e6706a09e100..8680abf72dd2 100644
> --- a/drivers/iio/adc/ad7793.c
> +++ b/drivers/iio/adc/ad7793.c
> @@ -257,7 +257,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
>  	unsigned int vref_mv)
>  {
>  	struct ad7793_state *st = iio_priv(indio_dev);
> -	int i, ret = -1;
> +	int i, ret;
>  	unsigned long long scale_uv;
>  	u32 id;
>  
> @@ -266,6 +266,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
>  		return ret;
>  
>  	/* reset the serial interface */
> +	ret = -1;
>  	ret = spi_write(st->sd.spi, (u8 *)&ret, sizeof(ret));
>  	if (ret < 0)
>  		goto out;

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

* Re: [PATCH] iio:ad7793: Fix the serial interface reset
  2017-09-04 15:26 ` Jonathan Cameron
@ 2017-09-04 15:33   ` Bogdan, Dragos
  0 siblings, 0 replies; 3+ messages in thread
From: Bogdan, Dragos @ 2017-09-04 15:33 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Hennerich, Michael, Jonathan Cameron,
	Hartmut Knaack, Peter Meerwald-Stadler, linux-iio, linux-kernel

On 09/04/2017 06:27 PM, Jonathan Cameron wrote:
> On Mon, 4 Sep 2017 18:00:48 +0300
> Dragos Bogdan <dragos.bogdan@analog.com> wrote:
>
>> The serial interface can be reset by writing 32 consecutive 1s to the device.
>> The value of 'ret' is overwritten when ad7793_check_platform_data() is called,
>> so it should be initialized to -1 only before doing the spi_write().
>>
>> Fixes: commit 2edb769d246e ("iio:ad7793: Add support for the ad7798 and ad7799")
>>
>> Signed-off-by: Dragos Bogdan <dragos.bogdan@analog.com>
> Hi Dragos,
>
> I'd prefer we introduced a separate variable.  Using ret for this
> is what got us into trouble in the first place.
>
> Would you mind respining with that change?
>
> Thanks,
>
> Jonathan

Hi Jonathan,

I agree with your suggestion. I'll change it accordingly in v2.

Thanks,
Dragos

>> ---
>>  drivers/iio/adc/ad7793.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/adc/ad7793.c b/drivers/iio/adc/ad7793.c
>> index e6706a09e100..8680abf72dd2 100644
>> --- a/drivers/iio/adc/ad7793.c
>> +++ b/drivers/iio/adc/ad7793.c
>> @@ -257,7 +257,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
>>  	unsigned int vref_mv)
>>  {
>>  	struct ad7793_state *st = iio_priv(indio_dev);
>> -	int i, ret = -1;
>> +	int i, ret;
>>  	unsigned long long scale_uv;
>>  	u32 id;
>>  
>> @@ -266,6 +266,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,
>>  		return ret;
>>  
>>  	/* reset the serial interface */
>> +	ret = -1;
>>  	ret = spi_write(st->sd.spi, (u8 *)&ret, sizeof(ret));
>>  	if (ret < 0)
>>  		goto out;
>
>

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

end of thread, other threads:[~2017-09-04 15:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-04 15:00 [PATCH] iio:ad7793: Fix the serial interface reset Dragos Bogdan
2017-09-04 15:26 ` Jonathan Cameron
2017-09-04 15:33   ` Bogdan, Dragos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®