[PATCH 5.1 29/85] iio: adc: ads124: avoid buffer overflow

From: Greg Kroah-Hartman
Date: Fri Jun 07 2019 - 11:54:03 EST


From: Vincent Stehlà <vincent.stehle@xxxxxxxxxxx>

commit 0db8aa49a97e7f40852a64fd35abcc1292a7c365 upstream.

When initializing the priv->data array starting from index 1, there is one
less element to consider than when initializing the full array.

Fixes: e717f8c6dfec8f76 ("iio: adc: Add the TI ads124s08 ADC code")
Signed-off-by: Vincent Stehlà <vincent.stehle@xxxxxxxxxxx>
Reviewed-by: Mukesh Ojha <mojha@xxxxxxxxxxxxxx>
Reviewed-by: Dan Murphy <dmurphy@xxxxxx>
Cc: <Stable@xxxxxxxxxxxxxxx>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
drivers/iio/adc/ti-ads124s08.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/iio/adc/ti-ads124s08.c
+++ b/drivers/iio/adc/ti-ads124s08.c
@@ -202,7 +202,7 @@ static int ads124s_read(struct iio_dev *
};

priv->data[0] = ADS124S08_CMD_RDATA;
- memset(&priv->data[1], ADS124S08_CMD_NOP, sizeof(priv->data));
+ memset(&priv->data[1], ADS124S08_CMD_NOP, sizeof(priv->data) - 1);

ret = spi_sync_transfer(priv->spi, t, ARRAY_SIZE(t));
if (ret < 0)