[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <5c7fcaa93c8184dd62beeccccfa07e144042fdc4.camel@gmail.com>
Date: Tue, 09 Jul 2024 09:41:18 +0200
From: Nuno Sá <noname.nuno@...il.com>
To: Marcelo Schmitt <marcelo.schmitt@...log.com>, broonie@...nel.org,
lars@...afoo.de, Michael.Hennerich@...log.com, jic23@...nel.org,
robh+dt@...nel.org, krzysztof.kozlowski+dt@...aro.org, conor+dt@...nel.org,
nuno.sa@...log.com, dlechner@...libre.com, corbet@....net,
marcelo.schmitt1@...il.com
Cc: linux-iio@...r.kernel.org, devicetree@...r.kernel.org,
linux-spi@...r.kernel.org, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6 6/7] iio: adc: Add support for AD4000
On Sat, 2024-06-29 at 16:06 -0300, Marcelo Schmitt wrote:
> Add support for AD4000 series of low noise, low power, high speed,
> successive approximation register (SAR) ADCs.
>
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@...log.com>
> ---
Hi Marcelo,
LGTM. Only one thing that needs to be addressed. With that,
Reviewed-by: Nuno Sa <nuno.sa@...log.com>
> MAINTAINERS | 1 +
> drivers/iio/adc/Kconfig | 12 +
> drivers/iio/adc/Makefile | 1 +
> drivers/iio/adc/ad4000.c | 708 +++++++++++++++++++++++++++++++++++++++
> 4 files changed, 722 insertions(+)
> create mode 100644 drivers/iio/adc/ad4000.c
>
...
>
> + st->gain_milli = 1000;
> + if (chip->has_hardware_gain &&
> + device_property_present(dev, "adi,gain-milli")) {
> + ret = device_property_read_u16(dev, "adi,gain-milli",
> + &st->gain_milli);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "Failed to read gain
> property\n");
> + }
The above is odd. Why not reading directly device_property_read_u16()? Skip the
call to device_property_present().
But most importantly, you're not doing any validation on gain_milli which is an
enum (by looking at the bindings). So in theory even 0 would be accepted which
would lead to a divide by 0 later on. I would do:
if (chip->has_hardware_gain) {
ret = device_property_read_u16(...)
if (!ret) {
/* validate here for a proper value /*
}
}
You can also check for ret < 0 and -EINVAL to detect an invalid devicetree
parameter instead of completely ignoring return codes (but for non mandatory
properties one typically does not care much - up to you)
- Nuno Sá
Powered by blists - more mailing lists