From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: "Matti Vaittinen" <matti.vaittinen@fi.rohmeurope.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH 1/2] iio: adc: ad7476: Simplify chip type detection
Date: Mon, 4 Aug 2025 08:57:37 +0300 [thread overview]
Message-ID: <e91711f6-c943-402a-8502-52d8ed4c05a9@gmail.com> (raw)
In-Reply-To: <20250801120901.00004a67@huawei.com>
On 01/08/2025 14:09, Jonathan Cameron wrote:
> On Fri, 1 Aug 2025 13:07:13 +0300
> Matti Vaittinen <mazziesaccount@gmail.com> wrote:
>
>> The ad7476 driver uses a table of structures for defining the IC variant
>> specific data. Table is indexed using enum values, which are picked by
>> SPI ID.
>>
>> Having the table and an enum adds extra complexity. It is potentially
>> unsafe if someone alters the enumeration values, or size of the IC data
>> table.
>>
>> Simplify this by dropping the table and using individual structures for
>> the IC specific data, and storing the IC specific structure's address
>> directly in the SPI ID data.
>>
>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>>
>> ---
>> 100% Untested.
>> No functional changes intended
>
> One tiny thing inline, otherwise looks good to me. This aligns with
> how we prefer to do things these days. Tends to end up easier to read
> than the enum array thing and best of all removes any temptation to use
> the enum for anything else.
>
>>
>> static const struct iio_info ad7476_info = {
>> @@ -312,7 +306,7 @@ static int ad7476_probe(struct spi_device *spi)
>>
>> st = iio_priv(indio_dev);
>> st->chip_info =
>> - &ad7476_chip_info_tbl[spi_get_device_id(spi)->driver_data];
>> + (struct ad7476_chip_info *)spi_get_device_id(spi)->driver_data;
>
> Switch to spi_get_device_match_data()
> which checks via generic firmware paths first (so DT here) and then the
> old school tables. Also returns a void * so gets rid of need to cast.
Ah. Right! Thanks!
> Only works with all pointers (or a lot of care) because a value 0 is a
> fail to match. So kind of enabled by your patch.
Yours,
-- Matti
next prev parent reply other threads:[~2025-08-04 5:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-01 10:06 [RFC PATCH 0/2] iio: adc: ad7476: Simplifications Matti Vaittinen
2025-08-01 10:07 ` [RFC PATCH 1/2] iio: adc: ad7476: Simplify chip type detection Matti Vaittinen
2025-08-01 11:09 ` Jonathan Cameron
2025-08-04 5:57 ` Matti Vaittinen [this message]
2025-08-04 8:33 ` Andy Shevchenko
2025-08-01 22:01 ` Andy Shevchenko
2025-08-04 5:56 ` Matti Vaittinen
2025-08-04 8:31 ` Andy Shevchenko
2025-08-01 10:07 ` [RFC PATCH 2/2] iio: adc: ad7476: Simplify scale handling Matti Vaittinen
2025-08-01 11:12 ` Jonathan Cameron
2025-08-05 16:09 ` David Lechner
2025-08-06 5:08 ` Matti Vaittinen
2025-08-01 12:23 ` [RFC PATCH 0/2] iio: adc: ad7476: Simplifications Nuno Sá
2025-08-02 10:59 ` Jonathan Cameron
2025-08-04 5:29 ` Matti Vaittinen
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=e91711f6-c943-402a-8502-52d8ed4c05a9@gmail.com \
--to=mazziesaccount@gmail.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=broonie@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=lgirdwood@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=nuno.sa@analog.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).