Skip to content

Commit 5fa6863

Browse files
committed
spi: Check we have a spi_device_id for each DT compatible
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 3ce6c9e ("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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent f1e5ecc commit 5fa6863

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

drivers/spi/spi.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,47 @@ int __spi_register_driver(struct module *owner, struct spi_driver *sdrv)
459459
{
460460
sdrv->driver.owner = owner;
461461
sdrv->driver.bus = &spi_bus_type;
462+
463+
/*
464+
* For Really Good Reasons we use spi: modaliases not of:
465+
* modaliases for DT so module autoloading won't work if we
466+
* don't have a spi_device_id as well as a compatible string.
467+
*/
468+
if (sdrv->driver.of_match_table) {
469+
const struct of_device_id *of_id;
470+
471+
for (of_id = sdrv->driver.of_match_table; of_id->compatible[0];
472+
of_id++) {
473+
const char *of_name;
474+
475+
/* Strip off any vendor prefix */
476+
of_name = strnchr(of_id->compatible,
477+
sizeof(of_id->compatible), ',');
478+
if (of_name)
479+
of_name++;
480+
else
481+
of_name = of_id->compatible;
482+
483+
if (sdrv->id_table) {
484+
const struct spi_device_id *spi_id;
485+
486+
for (spi_id = sdrv->id_table; spi_id->name[0];
487+
spi_id++)
488+
if (strcmp(spi_id->name, of_name) == 0)
489+
break;
490+
491+
if (spi_id->name[0])
492+
continue;
493+
} else {
494+
if (strcmp(sdrv->driver.name, of_name) == 0)
495+
continue;
496+
}
497+
498+
pr_warn("SPI driver %s has no spi_device_id for %s\n",
499+
sdrv->driver.name, of_id->compatible);
500+
}
501+
}
502+
462503
return driver_register(&sdrv->driver);
463504
}
464505
EXPORT_SYMBOL_GPL(__spi_register_driver);

0 commit comments

Comments
 (0)