This patch avoids that complaints similar to the following appear in the
system log:

sysfs: cannot create duplicate filename 
'/devices/pseudo_0/adapter0/host3/target3:0:0/3:0:0:133/driver'

Cc: Lee Duncan <ldun...@suse.com>
Cc: Hannes Reinecke <h...@suse.com>
Cc: Luis Chamberlain <mcg...@kernel.org>
Cc: Johannes Thumshirn <jthumsh...@suse.de>
Cc: Christoph Hellwig <h...@lst.de>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Signed-off-by: Bart Van Assche <bvanass...@acm.org>
---
 drivers/base/dd.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index edfc9f0b1180..b4212154a94b 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -645,6 +645,14 @@ int driver_probe_device(struct device_driver *drv, struct 
device *dev)
 {
        int ret = 0;
 
+       /*
+        * Several callers check the driver pointer without holding the
+        * device mutex. Hence check the driver pointer again while holding
+        * the device mutex.
+        */
+       if (dev->driver)
+               return dev->driver == drv;
+
        if (!device_is_registered(dev))
                return -ENODEV;
 
-- 
2.19.1.568.g152ad8e336-goog

Reply via email to