Skip to contentSkip to conversation

iio: adc: qcom-spmi-adc5: Verify channel numbers from DT

PATCH In review Matthias Kaehlcke 2 participants 2 messages Aug 27, 2018 – Sep 2, 2018

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

PATCH 1/1 iio: adc: qcom-spmi-adc5: Verify channel numbers from DT

The driver only defines a subset of all possible ADC channels. Channel numbers read from the device tree are accepted as long as they don't exceed a max value, even when no channel definition exists. Add a check to abort initialization in this case.

---
 drivers/iio/adc/qcom-spmi-adc5.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/qcom-spmi-adc5.c +2 -1
index 9c8e6f9e8248..ab5bec917c0a 100644
@@ -519,7 +519,8 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
 		return ret;
 	}
 
-	if (chan > ADC5_PARALLEL_ISENSE_VBAT_IDATA) {
+	if (chan > ADC5_PARALLEL_ISENSE_VBAT_IDATA ||
+	    !data->adc_chans[chan].datasheet_name) {
 		dev_err(dev, "%s invalid channel number %d\n", name, chan);
 		return -EINVAL;
 	}
Signature · 1 line
2.19.0.rc0.228.g281dcd1b4d0-goog
maintainer
#1 lore raw
Quoted 6 lines · On Mon, 27 Aug 2018 14:14:53 -0700 Matthias Kaehlcke <[email protected]> wrote:

The driver only defines a subset of all possible ADC channels. Channel numbers read from the device tree are accepted as long as they don't exceed a max value, even when no channel definition exists. Add a check to abort initialization in this case.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks for tidying this up.

Jonathan

Quoted 18 lines
---
 drivers/iio/adc/qcom-spmi-adc5.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/adc/qcom-spmi-adc5.c +2 -1
index 9c8e6f9e8248..ab5bec917c0a 100644
@@ -519,7 +519,8 @@ static int adc5_get_dt_channel_data(struct adc5_chip *adc,
 		return ret;
 	}
 
-	if (chan > ADC5_PARALLEL_ISENSE_VBAT_IDATA) {
+	if (chan > ADC5_PARALLEL_ISENSE_VBAT_IDATA ||
+	    !data->adc_chans[chan].datasheet_name) {
 		dev_err(dev, "%s invalid channel number %d\n", name, chan);
 		return -EINVAL;
 	}