All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: Check we have a spi_device_id for each DT compatible
@ 2021-09-21 19:21 Mark Brown
  2021-09-22 14:21 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Brown @ 2021-09-21 19:21 UTC (permalink / raw)
  To: linux-spi; +Cc: Mark Brown

Currently for SPI devices we use the spi_device_id for module autoloading
even on systems using device tree, meaning that listing a compatible string
in the of_match_table isn't enough to have the module for a SPI driver
autoloaded.

We attempted to fix this by generating OF based modaliases for devices
instantiated from DT in 3ce6c9e2617e ("spi: add of_device_uevent_modalias
support") but this meant we no longer reported spi_device_id based aliases
which broke drivers such as spi-nor which don't list all the compatible
strings they support directly for DT, and in at least that case it's not
super practical to do so given the very large number of compatibles
needed, much larger than the number spi_device_ids due to vendor strings.
As a result fell back to using spi_device_id based modalises.

Try to close the gap by printing a warning when a SPI driver has a DT
compatible that won't be matched as a SPI device ID with the goal of having
drivers provide both. Given fallback compatibles this check is going to be
excessive but it should be robust which is probably more important here.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/spi/spi.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 57e2499ec1ed..2c7f420b9f73 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -459,6 +459,47 @@ int __spi_register_driver(struct module *owner, struct spi_driver *sdrv)
 {
 	sdrv->driver.owner = owner;
 	sdrv->driver.bus = &spi_bus_type;
+
+	/*
+	 * For Really Good Reasons we use spi: modaliases not of:
+	 * modaliases for DT so module autoloading won't work if we
+	 * don't have a spi_device_id as well as a compatible string.
+	 */
+	if (sdrv->driver.of_match_table) {
+		const struct of_device_id *of_id;
+
+		for (of_id = sdrv->driver.of_match_table; of_id->compatible[0];
+		     of_id++) {
+			const char *of_name;
+
+			/* Strip off any vendor prefix */
+			of_name = strnchr(of_id->compatible,
+					  sizeof(of_id->compatible), ',');
+			if (of_name)
+				of_name++;
+			else
+				of_name = of_id->compatible;
+
+			if (sdrv->id_table) {
+				const struct spi_device_id *spi_id;
+
+				for (spi_id = sdrv->id_table; spi_id->name[0];
+				     spi_id++)
+					if (strcmp(spi_id->name, of_name) == 0)
+						break;
+
+				if (spi_id->name[0])
+					continue;
+			} else {
+				if (strcmp(sdrv->driver.name, of_name) == 0)
+					continue;
+			}
+
+			pr_warn("SPI driver %s has no spi_device_id for %s\n",
+				sdrv->driver.name, of_id->compatible);
+		}
+	}
+
 	return driver_register(&sdrv->driver);
 }
 EXPORT_SYMBOL_GPL(__spi_register_driver);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] spi: Check we have a spi_device_id for each DT compatible
  2021-09-21 19:21 [PATCH] spi: Check we have a spi_device_id for each DT compatible Mark Brown
@ 2021-09-22 14:21 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2021-09-22 14:21 UTC (permalink / raw)
  To: linux-spi, Mark Brown

On Tue, 21 Sep 2021 20:21:49 +0100, Mark Brown wrote:
> Currently for SPI devices we use the spi_device_id for module autoloading
> even on systems using device tree, meaning that listing a compatible string
> in the of_match_table isn't enough to have the module for a SPI driver
> autoloaded.
> 
> We attempted to fix this by generating OF based modaliases for devices
> instantiated from DT in 3ce6c9e2617e ("spi: add of_device_uevent_modalias
> support") but this meant we no longer reported spi_device_id based aliases
> which broke drivers such as spi-nor which don't list all the compatible
> strings they support directly for DT, and in at least that case it's not
> super practical to do so given the very large number of compatibles
> needed, much larger than the number spi_device_ids due to vendor strings.
> As a result fell back to using spi_device_id based modalises.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/1] spi: Check we have a spi_device_id for each DT compatible
      commit: 5fa6863ba69265cb7e45567d12614790ff26bd56

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-22 14:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-21 19:21 [PATCH] spi: Check we have a spi_device_id for each DT compatible Mark Brown
2021-09-22 14:21 ` Mark Brown

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.