iio: adc: stm32-dfsdm: add check on max filter id
authorFabrice Gasnier <fabrice.gasnier@st.com>
Fri, 23 Feb 2018 12:51:00 +0000 (13:51 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 28 Apr 2018 15:17:59 +0000 (16:17 +0100)
reg property should be checked against number of available filters.
BTW, dfsdm->num_fls wasn't used. But it can be used for this purpose.
This prevents using data out of allocated dfsdm->fl_list array.

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/stm32-dfsdm-adc.c

index df264e042bd88d2100a594eda26b7cf0c5ecceb8..cc8ab86c1caae5ed01f4375214d6d2108dfb270b 100644 (file)
@@ -1108,8 +1108,8 @@ static int stm32_dfsdm_adc_probe(struct platform_device *pdev)
        platform_set_drvdata(pdev, adc);
 
        ret = of_property_read_u32(dev->of_node, "reg", &adc->fl_id);
-       if (ret != 0) {
-               dev_err(dev, "Missing reg property\n");
+       if (ret != 0 || adc->fl_id >= adc->dfsdm->num_fls) {
+               dev_err(dev, "Missing or bad reg property\n");
                return -EINVAL;
        }