linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Subject: [PATCH] spi: spidev: Warn loudly if instantiated from DT as "spidev"
Date: Fri, 27 Mar 2015 16:42:22 -0700	[thread overview]
Message-ID: <1427499742-26916-1-git-send-email-broonie@kernel.org> (raw)

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 <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 drivers/spi/spidev.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index 23ad97807797..92c909eed6b5 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -703,6 +703,14 @@ static const struct file_operations spidev_fops = {
 
 static struct class *spidev_class;
 
+#ifdef CONFIG_OF
+static const struct of_device_id spidev_dt_ids[] = {
+	{ .compatible = "rohm,dh2228fv" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, spidev_dt_ids);
+#endif
+
 /*-------------------------------------------------------------------------*/
 
 static int spidev_probe(struct spi_device *spi)
@@ -711,6 +719,17 @@ static int spidev_probe(struct spi_device *spi)
 	int			status;
 	unsigned long		minor;
 
+	/*
+	 * spidev should never be referenced in DT without a specific
+	 * compatbile string, it is a Linux implementation thing
+	 * rather than a description of the hardware.
+	 */
+	if (spi->dev.of_node && !of_match_device(spidev_dt_ids, &spi->dev)) {
+		dev_err(&spi->dev, "buggy DT: spidev listed directly in DT\n");
+		WARN_ON(spi->dev.of_node &&
+			!of_match_device(spidev_dt_ids, &spi->dev));
+	}
+
 	/* Allocate driver data */
 	spidev = kzalloc(sizeof(*spidev), GFP_KERNEL);
 	if (!spidev)
@@ -777,13 +796,6 @@ static int spidev_remove(struct spi_device *spi)
 	return 0;
 }
 
-static const struct of_device_id spidev_dt_ids[] = {
-	{ .compatible = "rohm,dh2228fv" },
-	{},
-};
-
-MODULE_DEVICE_TABLE(of, spidev_dt_ids);
-
 static struct spi_driver spidev_spi_driver = {
 	.driver = {
 		.name =		"spidev",
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

             reply	other threads:[~2015-03-27 23:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-27 23:42 Mark Brown [this message]
     [not found] ` <1427499742-26916-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-04-23  7:21   ` [PATCH] spi: spidev: Warn loudly if instantiated from DT as "spidev" Martin Sperl
     [not found]     ` <7C2BEBF5-5169-4804-A7B8-DBCE2E9E8C70-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-04-23  7:42       ` Geert Uytterhoeven
     [not found]         ` <CAMuHMdUv0z=VOec+JbbRBeM9fg2TvQgRX4GefVbOZDoQoOECQQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-04-23  7:45           ` Geert Uytterhoeven
     [not found]             ` <CAMuHMdW5hgB7vFmMc6TRqJ2wwWZ0=S+OKdQQoucXakoSnVixtw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-04-23 10:36               ` Mark Brown
     [not found]                 ` <20150423103652.GT22845-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-04-23 13:21                   ` Martin Sperl
     [not found]                     ` <5538F1D6.7020503-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-04-23 13:36                       ` Mark Brown
     [not found]                         ` <5538F95A.20203@martin.sperl.org>
     [not found]                           ` <20150423181317.GZ22845@sirena.org.uk>
     [not found]                             ` <20150423181317.GZ22845-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-04-23 19:23                               ` Martin Sperl
     [not found]                             ` <81BCB930-E90B-4978-9593-7997B64F65CE@martin.sperl.org>
     [not found]                               ` <81BCB930-E90B-4978-9593-7997B64F65CE-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org>
2015-04-23 19:32                                 ` Mark Brown

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=1427499742-26916-1-git-send-email-broonie@kernel.org \
    --to=broonie-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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).