Skip to content

Commit 956b200

Browse files
committed
spi: spidev: Warn loudly if instantiated from DT as "spidev"
Since spidev is a detail of how Linux controls a device rather than a description of the hardware in the system we should never have a node described as "spidev" in DT, any SPI device could be a spidev so this is just not a useful description. In order to help prevent users from writing such device trees generate a warning if spidev is instantiated as a DT node without an ID in the match table. Signed-off-by: Mark Brown <[email protected]>
1 parent f20fbaa commit 956b200

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

drivers/spi/spidev.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,14 @@ static const struct file_operations spidev_fops = {
703703

704704
static struct class *spidev_class;
705705

706+
#ifdef CONFIG_OF
707+
static const struct of_device_id spidev_dt_ids[] = {
708+
{ .compatible = "rohm,dh2228fv" },
709+
{},
710+
};
711+
MODULE_DEVICE_TABLE(of, spidev_dt_ids);
712+
#endif
713+
706714
/*-------------------------------------------------------------------------*/
707715

708716
static int spidev_probe(struct spi_device *spi)
@@ -711,6 +719,17 @@ static int spidev_probe(struct spi_device *spi)
711719
int status;
712720
unsigned long minor;
713721

722+
/*
723+
* spidev should never be referenced in DT without a specific
724+
* compatbile string, it is a Linux implementation thing
725+
* rather than a description of the hardware.
726+
*/
727+
if (spi->dev.of_node && !of_match_device(spidev_dt_ids, &spi->dev)) {
728+
dev_err(&spi->dev, "buggy DT: spidev listed directly in DT\n");
729+
WARN_ON(spi->dev.of_node &&
730+
!of_match_device(spidev_dt_ids, &spi->dev));
731+
}
732+
714733
/* Allocate driver data */
715734
spidev = kzalloc(sizeof(*spidev), GFP_KERNEL);
716735
if (!spidev)
@@ -777,13 +796,6 @@ static int spidev_remove(struct spi_device *spi)
777796
return 0;
778797
}
779798

780-
static const struct of_device_id spidev_dt_ids[] = {
781-
{ .compatible = "rohm,dh2228fv" },
782-
{},
783-
};
784-
785-
MODULE_DEVICE_TABLE(of, spidev_dt_ids);
786-
787799
static struct spi_driver spidev_spi_driver = {
788800
.driver = {
789801
.name = "spidev",

0 commit comments

Comments
 (0)