Skip to contentSkip to conversation

iio:ad7793: Fix the serial interface reset

PATCH In review Dragos Bogdan 2 participants 3 messages Sep 4, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio:ad7793: Fix the serial interface reset

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")
---
 drivers/iio/adc/ad7793.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/ad7793.c +2 -1
index e6706a09e100..8680abf72dd2 100644
@@ -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;
Signature · 1 line
2.11.0
#1 lore raw
Quoted 7 lines · On Mon, 4 Sep 2017 18:00:48 +0300 Dragos Bogdan <[email protected]>…

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

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

Quoted 25 lines
---
 drivers/iio/adc/ad7793.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/ad7793.c +2 -1
index e6706a09e100..8680abf72dd2 100644
@@ -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 lore raw

On 09/04/2017 06:27 PM, Jonathan Cameron wrote:=0A=

Quoted 4 lines

On Mon, 4 Sep 2017 18:00:48 +0300=0A= Dragos Bogdan <[email protected]> wrote:=0A= =0A=

Quoted 1 line

The serial interface can be reset by writing 32 consecutive 1s to the de=

vice.=0A=

Quoted 1 line
Quoted 1 line

The value of 'ret' is overwritten when ad7793_check_platform_data() is c=

alled,=0A=

Quoted 3 lines
Quoted 3 lines

so it should be initialized to -1 only before doing the spi_write().=0A= =0A=

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

ad7799")=0A=

Quoted 12 lines
Quoted 2 lines

=0A=

Hi Dragos,=0A=
=0A=
I'd prefer we introduced a separate variable. Using ret for this=0A= is what got us into trouble in the first place.=0A=
=0A=
Would you mind respining with that change?=0A=
=0A=
Thanks,=0A=
=0A=
Jonathan=0A=

=0A=
Hi Jonathan,=0A=
=0A=
I agree with your suggestion. I'll change it accordingly in v2.=0A= =0A=
Thanks,=0A=
Dragos=0A=
=0A=

Quoted 9 lines

drivers/iio/adc/ad7793.c=0A= static int ad7793_setup(struct iio_dev *indio_dev,=

Quoted 9 lines

---=0A=
drivers/iio/adc/ad7793.c | 3 ++-=0A=

 1 file changed, 2 insertions(+), 1 deletion(-)=0A=

=0A=

drivers/iio/adc/ad7793.c=0A= +0 -0
index e6706a09e100..8680abf72dd2 100644=0A=
@@ -257,7 +257,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,=

=0A=

Quoted 9 lines

drivers/iio/adc/ad7793.c=0A= static int ad7793_setup(struct iio_dev *indio_dev,=

Quoted 9 lines
drivers/iio/adc/ad7793.c=0A= +1 -1
 	unsigned int vref_mv)=0A=
 {=0A=
 	struct ad7793_state *st =3D iio_priv(indio_dev);=0A=
-	int i, ret =3D -1;=0A=
+	int i, ret;=0A=
 	unsigned long long scale_uv;=0A=
 	u32 id;=0A=
 =0A=
@@ -266,6 +266,7 @@ static int ad7793_setup(struct iio_dev *indio_dev,=

=0A=

Quoted 9 lines

drivers/iio/adc/ad7793.c=0A= static int ad7793_setup(struct iio_dev *indio_dev,= · line 272

Quoted 7 lines
drivers/iio/adc/ad7793.c=0A= +1 -0
 		return ret;=0A=
 =0A=
 	/* reset the serial interface */=0A=
+	ret =3D -1;=0A=
 	ret =3D spi_write(st->sd.spi, (u8 *)&ret, sizeof(ret));=0A=
 	if (ret < 0)=0A=
 		goto out;=0A=

=0A=
=0A=