diff options
author | Jason Gunthorpe <jgg@nvidia.com> | 2021-06-17 16:22:09 +0200 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2021-06-21 23:29:24 +0200 |
commit | 204db60c83574559a8e08ce4bbd0029d56b8ab2e (patch) | |
tree | 3741c49db2424f57bb217eee62405067b361a9b7 /drivers/base/bus.c | |
parent | Linux 5.13-rc6 (diff) | |
download | linux-204db60c83574559a8e08ce4bbd0029d56b8ab2e.tar.xz linux-204db60c83574559a8e08ce4bbd0029d56b8ab2e.zip |
driver core: Pull required checks into driver_probe_device()
Checking if the dev is dead or if the dev is already bound is a required
precondition to invoking driver_probe_device(). All the call chains
leading here duplicate these checks.
Add it directly to driver_probe_device() so the precondition is clear and
remove the checks from device_driver_attach() and
__driver_attach_async_helper().
The other call chain going through __device_attach_driver() does have
these same checks but they are inlined into logic higher up the call stack
and can't be removed.
The sysfs uAPI call chain starting at bind_store() is a bit confused
because it reads dev->driver unlocked and returns -ENODEV if it is !NULL,
otherwise it reads it again under lock and returns 0 if it is !NULL. Fix
this to always return -EBUSY and always read dev->driver under its lock.
Done in preparation for the next patches which will add additional
callers to driver_probe_device() and will need these checks as well.
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
[hch: drop the extra checks in device_driver_attach and bind_store]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Link: https://lore.kernel.org/r/20210617142218.1877096-2-hch@lst.de
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/base/bus.c')
-rw-r--r-- | drivers/base/bus.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 36d0c654ea61..7de13302e8c8 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -210,7 +210,7 @@ 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 && driver_match_device(drv, dev)) { err = device_driver_attach(drv, dev); if (err > 0) { |