All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Janani Sunil <janani.sunil@analog.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Mark Brown" <broonie@kernel.org>,
	"Marius Cristea" <marius.cristea@microchip.com>,
	"Marcus Folkesson" <marcus.folkesson@gmail.com>,
	"Kent Gustavsson" <kent@minoris.se>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	"Janani Sunil" <jan.sun97@gmail.com>,
	linux-spi@vger.kernel.org, "Kent Gustavsson" <nedo80@gmail.com>
Subject: Re: [PATCH v7 7/7] iio: dac: Add AD5529R DAC driver support
Date: Sat, 25 Jul 2026 00:57:14 +0100	[thread overview]
Message-ID: <20260725005714.034b50bf@jic23-huawei> (raw)
In-Reply-To: <20260722-ad5529r-driver-v7-7-7781cd74ad75@analog.com>

On Wed, 22 Jul 2026 09:54:19 +0200
Janani Sunil <janani.sunil@analog.com> wrote:

> Add support for AD5529R 16-channel, 12/16 bit Digital to Analog Converter
> from Analog Devices.
> 
> The device communicates over SPI and supports per-channel output range
> configuration. An optional external 4.096V reference can be used in
> place of the internal reference.
> 
> Signed-off-by: Janani Sunil <janani.sunil@analog.com>

Sashiko had one comment that I think deserves a tiny modification.

Otherwise looks good to me.

I would have just tweaked that and  the [] (and still may) bit giving time for that SPI
ack from Mark for the generic property before I pick this series up.

Feel free to send a new version if you prefer.

Thanks,

Jonathan


> diff --git a/drivers/iio/dac/ad5529r.c b/drivers/iio/dac/ad5529r.c
> new file mode 100644
> index 000000000000..2fd1dd053da5
> --- /dev/null
> +++ b/drivers/iio/dac/ad5529r.c

> +
> +static int ad5529r_parse_channel_ranges(struct device *dev,
> +					struct ad5529r_state *st)
> +{
> +	s32 vals[2];
> +	int ret, range_idx;
> +	u32 ch;
> +
> +	device_for_each_child_node_scoped(dev, child) {

As below, lets check we don't come in here once too many.
		if (st->num_channels == ARRAY_SIZE(st->channels))
			return dev_err_probe(dev, -EINVAL, "Too many channels\n");

> +		ret = fwnode_property_read_u32(child, "reg", &ch);
> +		if (ret)
> +			return dev_err_probe(dev, ret,
> +					     "Missing reg property in channel node\n");
> +
> +		if (ch >= 16)
> +			return dev_err_probe(dev, -EINVAL,
> +					     "Channel %u exceeds maximum 15\n",
> +					     ch);
> +
> +		if (fwnode_property_present(child, "output-range-microvolt")) {
> +			/*
> +			 * DT stores cells as raw 32-bit values; signed endpoints are
> +			 * encoded by dtc in two's-complement and then interpreted
> +			 * here as s32.
> +			 */
> +			ret = fwnode_property_read_u32_array(child,
> +							     "output-range-microvolt",
> +							     (u32 *)vals, ARRAY_SIZE(vals));
> +			if (ret < 0)
> +				return dev_err_probe(dev, ret,
> +						     "Failed to read range for ch %u\n",
> +						     ch);
> +
> +			range_idx = ad5529r_find_output_range(vals);
> +			if (range_idx < 0)
> +				return dev_err_probe(dev, range_idx,
> +						     "Invalid range [%d %d] for ch %u\n",
> +						     vals[0], vals[1], ch);
> +		} else {
> +			range_idx = AD5529R_RANGE_0V_5V;
> +		}
> +
> +		st->output_range_idx[ch] = range_idx;
> +		ret = regmap_write(st->regmap_16bit,
> +				   AD5529R_REG_OUT_RANGE(ch), range_idx);
> +		if (ret)
> +			return dev_err_probe(dev, ret,
> +					     "Failed to configure range for ch %u\n",
> +					     ch);
> +
> +		st->channels[st->num_channels++] = AD5529R_DAC_CHANNEL(ch);

Sashiko calls out that a malformed DT could have repeat entries and so overflow channels.
Given it is easy to harden against that, let us do so alongside that check on
if (ch < 16) above.

> +	}
> +
> +	return 0;
> +}

      parent reply	other threads:[~2026-07-24 23:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22  7:54 [PATCH v7 0/7] iio: dac: Add support for AD5529R DAC Janani Sunil
2026-07-22  7:54 ` [PATCH v7 1/7] spi: dt-bindings: Add spi-device-addr peripheral property Janani Sunil
2026-07-22 16:39   ` Conor Dooley
2026-07-23  5:48   ` Marcus Folkesson
2026-07-24 23:32   ` Jonathan Cameron
2026-07-22  7:54 ` [PATCH v7 2/7] dt-bindings: iio: adc: microchip,mcp3564: Add spi-device-addr Janani Sunil
2026-07-22  8:05   ` sashiko-bot
2026-07-22 16:40   ` Conor Dooley
2026-07-22  7:54 ` [PATCH v7 3/7] iio: adc: mcp3564: Add support for spi-device-addr Janani Sunil
2026-07-22 16:45   ` Conor Dooley
2026-07-22 17:02     ` Marius.Cristea
2026-07-22 17:12       ` Conor Dooley
2026-07-22 17:06   ` Marius.Cristea
2026-07-22  7:54 ` [PATCH v7 4/7] dt-bindings: iio: adc: microchip,mcp3911: Add spi-device-addr Janani Sunil
2026-07-22  8:05   ` sashiko-bot
2026-07-22 16:41   ` Conor Dooley
2026-07-23  5:46   ` Marcus Folkesson
2026-07-22  7:54 ` [PATCH v7 5/7] iio: adc: mcp3911: Add support for spi-device-addr Janani Sunil
2026-07-22 16:41   ` Conor Dooley
2026-07-22 16:43     ` Conor Dooley
2026-07-22 17:18       ` Marius.Cristea
2026-07-22 17:19   ` Marius.Cristea
2026-07-23  5:44   ` Marcus Folkesson
2026-07-22  7:54 ` [PATCH v7 6/7] dt-bindings: iio: dac: Add AD5529R Janani Sunil
2026-07-22  8:11   ` sashiko-bot
2026-07-22 16:39   ` Conor Dooley
2026-07-22  7:54 ` [PATCH v7 7/7] iio: dac: Add AD5529R DAC driver support Janani Sunil
2026-07-22  8:14   ` sashiko-bot
2026-07-24 23:57   ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260725005714.034b50bf@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jan.sun97@gmail.com \
    --cc=janani.sunil@analog.com \
    --cc=kent@minoris.se \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=marcus.folkesson@gmail.com \
    --cc=marius.cristea@microchip.com \
    --cc=nedo80@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.