From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Mark Brown <broonie@kernel.org>, <linux-spi@vger.kernel.org>,
<linux-kernel@vger.kernel.org>,
Wei Yongjun <weiyongjun@huaweicloud.com>,
Jonathan Cameron <jic23@kernel.org>, <linux-iio@vger.kernel.org>
Subject: Re: [PATCH v1 1/1] spi: Introduce spi_get_device_match_data() helper
Date: Thu, 22 Sep 2022 12:18:50 +0100 [thread overview]
Message-ID: <20220922121850.000006f3@huawei.com> (raw)
In-Reply-To: <20220921204520.23984-1-andriy.shevchenko@linux.intel.com>
On Wed, 21 Sep 2022 23:45:20 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> The proposed spi_get_device_match_data() helper is for retrieving
> a driver data associated with the ID in an ID table. First, it tries
> to get driver data of the device enumerated by firmware interface
> (usually Device Tree or ACPI). If none is found it falls back to
> the SPI ID table matching.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
I like this in general, but we need to keep a close eye on usecases
that are introduced to make sure that there is alignment between the
contents of the tables.
Perhaps the text should also explain a bit about why we would allow
both paths (in many case, the fallback will work fine)...
Previously a strong reason for that was that there was nothing to ensure
that all dt table entries were mirrored in the spi_device_id table.
As a side effect of the check to ensure module autoloading works, there
is now a check for that.
My personal view is we should still use the more generic path, even if
magic under the hood puts the data in spi_id->driver_data.
Jonathan
> ---
> drivers/spi/spi.c | 12 ++++++++++++
> include/linux/spi/spi.h | 3 +++
> 2 files changed, 15 insertions(+)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index ad254b94308e..a0947d63afbc 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -360,6 +360,18 @@ const struct spi_device_id *spi_get_device_id(const struct spi_device *sdev)
> }
> EXPORT_SYMBOL_GPL(spi_get_device_id);
>
> +const void *spi_get_device_match_data(const struct spi_device *sdev)
> +{
> + const void *match;
> +
> + match = device_get_match_data(&sdev->dev);
> + if (match)
> + return match;
> +
> + return (const void *)spi_get_device_id(sdev)->driver_data;
> +}
> +EXPORT_SYMBOL_GPL(spi_get_device_match_data);
> +
> static int spi_match_device(struct device *dev, struct device_driver *drv)
> {
> const struct spi_device *spi = to_spi_device(dev);
> diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
> index 6ea889df0813..f2565c24ef27 100644
> --- a/include/linux/spi/spi.h
> +++ b/include/linux/spi/spi.h
> @@ -1510,6 +1510,9 @@ extern void spi_unregister_device(struct spi_device *spi);
> extern const struct spi_device_id *
> spi_get_device_id(const struct spi_device *sdev);
>
> +extern const void *
> +spi_get_device_match_data(const struct spi_device *sdev);
> +
> static inline bool
> spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer)
> {
prev parent reply other threads:[~2022-09-22 11:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 20:45 [PATCH v1 1/1] spi: Introduce spi_get_device_match_data() helper Andy Shevchenko
2022-09-21 23:30 ` kernel test robot
2022-09-22 3:45 ` kernel test robot
2022-09-22 5:34 ` kernel test robot
2022-09-22 11:18 ` 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=20220922121850.000006f3@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=broonie@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=weiyongjun@huaweicloud.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).