[PATCH v6 5/6] iio: adc: ad7606: exit for invalid fdt dt_schema properties

Angelo Dureghello posted 6 patches 6 months, 3 weeks ago
There is a newer version of this series
[PATCH v6 5/6] iio: adc: ad7606: exit for invalid fdt dt_schema properties
Posted by Angelo Dureghello 6 months, 3 weeks ago
From: Angelo Dureghello <adureghello@baylibre.com>

Fix ad7606_get_chan_config() fdt parsing function to exit for error in
case of invalid dt_schema values.

Idea is to not allowing to proceed over when there are values that are
not allowed from the dt_schema.

Fixes: f3838e934dff ("iio: adc: ad7606: add support for AD7606C-{16,18} parts")
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
---
 drivers/iio/adc/ad7606.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
index bb0c89fc618874f4a5948d8e537716f87127bc92..f832fd0daf50a69a892636018bda2e43f73d1570 100644
--- a/drivers/iio/adc/ad7606.c
+++ b/drivers/iio/adc/ad7606.c
@@ -319,15 +319,13 @@ static int ad7606_get_chan_config(struct iio_dev *indio_dev, int ch,
 
 		ret = fwnode_property_read_u32(child, "reg", &reg);
 		if (ret)
-			continue;
+			return ret;
 
 		/* channel number (here) is from 1 to num_channels */
-		if (reg < 1 || reg > num_channels) {
-			dev_warn(dev,
-				 "Invalid channel number (ignoring): %d\n", reg);
-			continue;
-		}
+		if (reg < 1 || reg > num_channels)
+			return -EINVAL;
 
+		/* Loop until we are in the right channel. */
 		if (reg != (ch + 1))
 			continue;
 

-- 
2.49.0
Re: [PATCH v6 5/6] iio: adc: ad7606: exit for invalid fdt dt_schema properties
Posted by Jonathan Cameron 6 months, 3 weeks ago
On Thu, 22 May 2025 15:27:06 +0200
Angelo Dureghello <adureghello@baylibre.com> wrote:

> From: Angelo Dureghello <adureghello@baylibre.com>
> 
> Fix ad7606_get_chan_config() fdt parsing function to exit for error in
> case of invalid dt_schema values.
> 
> Idea is to not allowing to proceed over when there are values that are
> not allowed from the dt_schema.

"Idea is to not proceed when there are values that are not allowed
under the dt_shema."

> 
> Fixes: f3838e934dff ("iio: adc: ad7606: add support for AD7606C-{16,18} parts")

I'm in favour of consistency but it's only a 'fix' in the sense of blocking
bad DT cleanly.  So I don't think the Fixes tag is appropriate here.

> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>

> ---
>  drivers/iio/adc/ad7606.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/adc/ad7606.c b/drivers/iio/adc/ad7606.c
> index bb0c89fc618874f4a5948d8e537716f87127bc92..f832fd0daf50a69a892636018bda2e43f73d1570 100644
> --- a/drivers/iio/adc/ad7606.c
> +++ b/drivers/iio/adc/ad7606.c
> @@ -319,15 +319,13 @@ static int ad7606_get_chan_config(struct iio_dev *indio_dev, int ch,
>  
>  		ret = fwnode_property_read_u32(child, "reg", &reg);
>  		if (ret)
> -			continue;
> +			return ret;
>  
>  		/* channel number (here) is from 1 to num_channels */
> -		if (reg < 1 || reg > num_channels) {
> -			dev_warn(dev,
> -				 "Invalid channel number (ignoring): %d\n", reg);
> -			continue;
> -		}
> +		if (reg < 1 || reg > num_channels)
> +			return -EINVAL;
>  
> +		/* Loop until we are in the right channel. */
>  		if (reg != (ch + 1))
>  			continue;
>  
>