Skip to content

Commit 279c3a2

Browse files
Dan Carpenterjic23
authored andcommitted
iio: adc: palmas: fix off by one bugs
Valid values for "adc_chan" are zero to (PALMAS_ADC_CH_MAX - 1). Smatch detects some buffer overflows caused by this: drivers/iio/adc/palmas_gpadc.c:721 palmas_gpadc_read_event_value() error: buffer overflow 'adc->thresholds' 16 <= 16 drivers/iio/adc/palmas_gpadc.c:758 palmas_gpadc_write_event_value() error: buffer overflow 'adc->thresholds' 16 <= 16 The effect of this bug in other functions is more complicated but obviously we should fix all of them. Fixes: a99544c ("iio: adc: palmas: add support for iio threshold events") Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 27b2ed5 commit 279c3a2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/iio/adc/palmas_gpadc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ static int palmas_gpadc_read_raw(struct iio_dev *indio_dev,
547547
int adc_chan = chan->channel;
548548
int ret = 0;
549549

550-
if (adc_chan > PALMAS_ADC_CH_MAX)
550+
if (adc_chan >= PALMAS_ADC_CH_MAX)
551551
return -EINVAL;
552552

553553
mutex_lock(&adc->lock);
@@ -595,7 +595,7 @@ static int palmas_gpadc_read_event_config(struct iio_dev *indio_dev,
595595
int adc_chan = chan->channel;
596596
int ret = 0;
597597

598-
if (adc_chan > PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH)
598+
if (adc_chan >= PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH)
599599
return -EINVAL;
600600

601601
mutex_lock(&adc->lock);
@@ -684,7 +684,7 @@ static int palmas_gpadc_write_event_config(struct iio_dev *indio_dev,
684684
int adc_chan = chan->channel;
685685
int ret;
686686

687-
if (adc_chan > PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH)
687+
if (adc_chan >= PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH)
688688
return -EINVAL;
689689

690690
mutex_lock(&adc->lock);
@@ -710,7 +710,7 @@ static int palmas_gpadc_read_event_value(struct iio_dev *indio_dev,
710710
int adc_chan = chan->channel;
711711
int ret;
712712

713-
if (adc_chan > PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH)
713+
if (adc_chan >= PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH)
714714
return -EINVAL;
715715

716716
mutex_lock(&adc->lock);
@@ -744,7 +744,7 @@ static int palmas_gpadc_write_event_value(struct iio_dev *indio_dev,
744744
int old;
745745
int ret;
746746

747-
if (adc_chan > PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH)
747+
if (adc_chan >= PALMAS_ADC_CH_MAX || type != IIO_EV_TYPE_THRESH)
748748
return -EINVAL;
749749

750750
mutex_lock(&adc->lock);

0 commit comments

Comments
 (0)