[PATCH v2 2/3] spi: Automatically attempt attach after driver_override alteration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When driver_override is set, call device_attach() to attempt to bind to
the new driver.  Presumably, that is why driver_override was set.

This makes driver_override easier to use from udev rules to bind a
device to a new driver.

This will not unbind from an existing driver.

Signed-off-by: Trent Piepho <tpiepho@xxxxxxxxxx>
---
 drivers/spi/spi.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 823fc130248b..5bac7a28b6e9 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -86,6 +86,7 @@ static ssize_t driver_override_store(struct device *dev,
 	const char *end = memchr(buf, '\n', count);
 	const size_t len = end ? end - buf : count;
 	const char *driver_override, *old;
+	int ret;
 
 	/* We need to keep extra room for a newline when displaying value */
 	if (len >= (PAGE_SIZE - 1))
@@ -107,6 +108,12 @@ static ssize_t driver_override_store(struct device *dev,
 	device_unlock(dev);
 	kfree(old);
 
+	/* Attach device to new driver if it's not already attached */
+	ret = device_attach(dev);
+	if (ret < 0 && ret != -EPROBE_DEFER)
+		dev_warn(dev, "device attach to '%s' failed (%d)\n",
+			 spi->driver_override, ret);
+
 	return count;
 }
 
-- 
2.14.4





[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux