All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Suchanek <hramrach@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Mark Brown <broonie@kernel.org>, Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Dan Williams <dan.j.williams@intel.com>,
	Tejun Heo <tj@kernel.org>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Nikolay Aleksandrov <nikolay@cumulusnetworks.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Adrien Schildknecht <adrien+dev@schischi.me>,
	linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org
Cc: Michal Suchanek <hramrach@gmail.com>
Subject: [PATCH 3/3] drivers core: allow id match override when manually binding driver
Date: Fri, 24 Jun 2016 16:20:34 +0200	[thread overview]
Message-ID: <5e0397742f887f656d67bb0d61c8e10782c0e5af.1466696079.git.hramrach@gmail.com> (raw)
In-Reply-To: <cover.1466696079.git.hramrach@gmail.com>
In-Reply-To: <cover.1466696079.git.hramrach@gmail.com>

This allows binding spidev on any slave device by hand using sysfs
without adding superfluous compatibles or any other needless
complication.

Note that any slave driver that requires configuration will fail to
probe anyway. Only a driver that binds to anything can be bound
successfully.

Signed-off-by: Michal Suchanek <hramrach@gmail.com>
---
 drivers/base/Kconfig.debug | 14 +++++++++
 drivers/base/bus.c         | 72 +++++++++++++++++++++++++++++++++++++++++++++-
 lib/Kconfig.debug          |  2 ++
 3 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 drivers/base/Kconfig.debug

diff --git a/drivers/base/Kconfig.debug b/drivers/base/Kconfig.debug
new file mode 100644
index 0000000..e21d3cc
--- /dev/null
+++ b/drivers/base/Kconfig.debug
@@ -0,0 +1,14 @@
+menuconfig DRIVER_MATCH_OVERRIDE
+	bool "Allow manual driver binding to override id match (DANGEROUS)"
+	default n
+	help
+	  When binding a driver manually bypass the check of driver id table
+	  against device id in driver core. This can be useful for development
+	  or on buses that don't provide reliable device identification.
+
+config DRIVER_MATCH_OVERRIDE_BUSES
+	string "Specify buses for which id matching will be overridden"
+	default "spi"
+	depends on DRIVER_MATCH_OVERRIDE
+	help
+	  space separated bus names
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 6470eb8..752c2a0 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -199,6 +199,73 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
 }
 static DRIVER_ATTR_WO(unbind);
 
+#ifdef CONFIG_DRIVER_MATCH_OVERRIDE_BUSES
+
+/* nul separated "" terminated strings */
+static const char *driver_override_buses;
+
+static inline void init_overrides(void)
+{
+	const char *buses_str = CONFIG_DRIVER_MATCH_OVERRIDE_BUSES;
+	char *transcript;
+	int i, len = strlen(buses_str);
+
+	if (!len)
+		return;
+
+	transcript = kzalloc(len + 1, GFP_KERNEL);
+	if (!transcript)
+		return;
+	driver_override_buses = transcript;
+
+	for (i = 0; i < len; i++) {
+
+		while (buses_str[i] == ' ')
+			i++;
+
+		if (buses_str[i]) {
+			const char *name_start = buses_str + i;
+			const char *name_end = strchrnul(name_start, ' ');
+			int name_len = name_end - name_start;
+
+			strncpy(transcript, name_start, name_len);
+			i += name_len;
+			transcript += name_len;
+			transcript++;
+		}
+	}
+}
+
+static inline bool driver_match_override(struct device_driver *drv,
+					 struct device *dev)
+{
+	struct bus_type *bus = bus_get(drv->bus);
+	const char *cmp_name = driver_override_buses;
+
+	while (cmp_name && *cmp_name) {
+		if (!strcmp(bus->name, cmp_name)) {
+			pr_notice("Overriding id match on manual driver binding:\n bus: %s  driver: %s  device: %s\n",
+				  bus->name, drv->name, dev_name(dev));
+			return true;
+		}
+		cmp_name += strlen(cmp_name);
+		cmp_name++;
+	}
+
+	return false;
+}
+
+#else /*CONFIG_DRIVER_MATCH_OVERRIDE_BUSES*/
+
+static inline void init_overrides(void)
+{}
+
+static inline bool driver_match_override(struct device_driver *drv,
+					 struct device *dev)
+{ return false; }
+
+#endif
+
 /*
  * Manually attach a device to a driver.
  * Note: the driver must want to bind to the device,
@@ -212,7 +279,8 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
 	int err = -ENODEV;
 
 	dev = bus_find_device_by_name(bus, NULL, buf);
-	if (dev && dev->driver == NULL && driver_match_device(drv, dev)) {
+	if (dev && dev->driver == NULL && (driver_match_device(drv, dev)
+	    || driver_match_override(drv, dev))) {
 		if (dev->parent)	/* Needed for USB */
 			device_lock(dev->parent);
 		device_lock(dev);
@@ -1280,5 +1348,7 @@ int __init buses_init(void)
 	if (!system_kset)
 		return -ENOMEM;
 
+	init_overrides();
+
 	return 0;
 }
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 1e9a607..f388212 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2002,3 +2002,5 @@ config IO_STRICT_DEVMEM
 	  if the driver using a given range cannot be disabled.
 
 	  If in doubt, say Y.
+
+source drivers/base/Kconfig.debug
-- 
2.8.1

  parent reply	other threads:[~2016-06-24 14:21 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-24 14:20 [PATCH 0/3] Another stab at making spidev usable with devicetree Michal Suchanek
2016-06-24 14:20 ` Michal Suchanek
2016-06-24 14:20 ` [PATCH 1/3] spi: spidev: fix the check for spidev in dt Michal Suchanek
2016-06-26  1:09   ` Mark Brown
2016-06-26  1:56     ` Michal Suchanek
2016-06-26  1:56       ` Michal Suchanek
2016-06-26  1:13   ` Mark Brown
2016-06-26  1:13     ` Mark Brown
2016-06-26  2:12     ` Michal Suchanek
2016-06-26  2:12       ` Michal Suchanek
2016-06-26 11:05       ` Mark Brown
2016-06-26 11:05         ` Mark Brown
2016-06-24 14:20 ` [PATCH 2/3] spi: of: allow instantiating slaves without a driver Michal Suchanek
2016-06-26  1:15   ` Mark Brown
2016-06-26  1:15     ` Mark Brown
2016-06-26  2:23     ` Michal Suchanek
2016-06-26  2:23       ` Michal Suchanek
2016-06-26 11:21       ` Mark Brown
2016-06-26 11:21         ` Mark Brown
2016-06-26 11:35         ` Michal Suchanek
2016-06-26 11:58           ` Mark Brown
2016-06-26 12:39             ` Michal Suchanek
2016-06-26 12:39               ` Michal Suchanek
2016-06-26 12:45               ` Mark Brown
2016-06-26 12:45                 ` Mark Brown
2016-06-26 12:53                 ` Michal Suchanek
2016-06-26 12:57                   ` Mark Brown
2016-06-26 12:57                     ` Mark Brown
2016-06-26 15:19                     ` Michal Suchanek
2016-06-26 15:19                       ` Michal Suchanek
2016-06-26 17:25                       ` Mark Brown
2016-06-26 17:25                         ` Mark Brown
2016-06-24 14:20 ` Michal Suchanek [this message]
2016-06-26  1:17   ` [PATCH 3/3] drivers core: allow id match override when manually binding driver Mark Brown
2016-06-26  1:17     ` Mark Brown
2016-06-26  4:14   ` Dan Williams
2016-06-26  6:44     ` Michal Suchanek
2016-06-26  6:44       ` Michal Suchanek
2016-06-26  9:26       ` Geert Uytterhoeven
2016-06-26  9:26         ` Geert Uytterhoeven
2016-06-26 18:28   ` Greg Kroah-Hartman
2016-06-26 18:28     ` Greg Kroah-Hartman
2016-06-26 19:07     ` Michal Suchanek
2016-06-26 19:07       ` Michal Suchanek
2016-06-27 19:09       ` Greg Kroah-Hartman
2016-06-27 19:09         ` Greg Kroah-Hartman

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=5e0397742f887f656d67bb0d61c8e10782c0e5af.1466696079.git.hramrach@gmail.com \
    --to=hramrach@gmail.com \
    --cc=adrien+dev@schischi.me \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=broonie@kernel.org \
    --cc=dan.j.williams@intel.com \
    --cc=dave@stgolabs.net \
    --cc=dvyukov@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=nikolay@cumulusnetworks.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=tj@kernel.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 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.