diff mbox series

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

Message ID 20180920191759.17781-3-tpiepho@impinj.com (mailing list archive)
State New, archived
Headers show
Series device tree spidev solution - driver_override for SPI | expand

Commit Message

Trent Piepho Sept. 20, 2018, 7:18 p.m. UTC
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@impinj.com>
---
 drivers/spi/spi.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Jan Kundrát Sept. 20, 2018, 9:38 p.m. UTC | #1
On čtvrtek 20. září 2018 21:18:33 CEST, Trent Piepho wrote:
> 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@impinj.com>

Reviewed-by: Jan Kundrát <jan.kundrat@cesnet.cz>
Tested-by: Jan Kundrát <jan.kundrat@cesnet.cz>
Geert Uytterhoeven Sept. 24, 2018, 8:02 a.m. UTC | #2
On Thu, Sep 20, 2018 at 9:18 PM Trent Piepho <tpiepho@impinj.com> wrote:
> 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@impinj.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert
Mark Brown Oct. 10, 2018, 11:37 a.m. UTC | #3
On Thu, Sep 20, 2018 at 07:18:33PM +0000, Trent Piepho wrote:
> 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.

How did things go with making this change to platform and other buses?
I'm not seeing anything in -next and my mailing list searches turned up
a blank.
diff mbox series

Patch

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;
 }