Commit 0d9f837c authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson

driver core: Export device_driver_attach()

This is intended as a replacement API for device_bind_driver(). It has at
least the following benefits:

- Internal locking. Few of the users of device_bind_driver() follow the
  locking rules

- Calls device driver probe() internally. Notably this means that devm
  support for probe works correctly as probe() error will call
  devres_release_all()

- struct device_driver -> dev_groups is supported

- Simplified calling convention, no need to manually call probe().

The general usage is for situations that already know what driver to bind
and need to ensure the bind is synchronized with other logic. Call
device_driver_attach() after device_add().

If probe() returns a failure then this will be preserved up through to the
error return of device_driver_attach().
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarCornelia Huck <cohuck@redhat.com>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20210617142218.1877096-6-hch@lst.deSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent 45ddcb42
...@@ -152,7 +152,6 @@ extern int driver_add_groups(struct device_driver *drv, ...@@ -152,7 +152,6 @@ extern int driver_add_groups(struct device_driver *drv,
const struct attribute_group **groups); const struct attribute_group **groups);
extern void driver_remove_groups(struct device_driver *drv, extern void driver_remove_groups(struct device_driver *drv,
const struct attribute_group **groups); const struct attribute_group **groups);
int device_driver_attach(struct device_driver *drv, struct device *dev);
void device_driver_detach(struct device *dev); void device_driver_detach(struct device *dev);
extern char *make_class_name(const char *name, struct kobject *kobj); extern char *make_class_name(const char *name, struct kobject *kobj);
......
...@@ -471,6 +471,8 @@ static void driver_sysfs_remove(struct device *dev) ...@@ -471,6 +471,8 @@ static void driver_sysfs_remove(struct device *dev)
* (It is ok to call with no other effort from a driver's probe() method.) * (It is ok to call with no other effort from a driver's probe() method.)
* *
* This function must be called with the device lock held. * This function must be called with the device lock held.
*
* Callers should prefer to use device_driver_attach() instead.
*/ */
int device_bind_driver(struct device *dev) int device_bind_driver(struct device *dev)
{ {
...@@ -1065,6 +1067,7 @@ int device_driver_attach(struct device_driver *drv, struct device *dev) ...@@ -1065,6 +1067,7 @@ int device_driver_attach(struct device_driver *drv, struct device *dev)
return -EAGAIN; return -EAGAIN;
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(device_driver_attach);
static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie) static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie)
{ {
......
...@@ -845,6 +845,8 @@ static inline void *dev_get_platdata(const struct device *dev) ...@@ -845,6 +845,8 @@ static inline void *dev_get_platdata(const struct device *dev)
* Manual binding of a device to driver. See drivers/base/bus.c * Manual binding of a device to driver. See drivers/base/bus.c
* for information on use. * for information on use.
*/ */
int __must_check device_driver_attach(struct device_driver *drv,
struct device *dev);
int __must_check device_bind_driver(struct device *dev); int __must_check device_bind_driver(struct device *dev);
void device_release_driver(struct device *dev); void device_release_driver(struct device *dev);
int __must_check device_attach(struct device *dev); int __must_check device_attach(struct device *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment