dd.c (c441bfb5f2866de71e092c1b9d866a65978dfe1a) | dd.c (204db60c83574559a8e08ce4bbd0029d56b8ab2e) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * drivers/base/dd.c - The core device/driver interactions. 4 * 5 * This file contains the (sometimes tricky) code that controls the 6 * interactions between devices and drivers, which primarily includes 7 * driver binding and unbinding. 8 * --- 719 unchanged lines hidden (view full) --- 728} 729EXPORT_SYMBOL_GPL(wait_for_device_probe); 730 731/** 732 * driver_probe_device - attempt to bind device & driver together 733 * @drv: driver to bind a device to 734 * @dev: device to try to bind to the driver 735 * | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * drivers/base/dd.c - The core device/driver interactions. 4 * 5 * This file contains the (sometimes tricky) code that controls the 6 * interactions between devices and drivers, which primarily includes 7 * driver binding and unbinding. 8 * --- 719 unchanged lines hidden (view full) --- 728} 729EXPORT_SYMBOL_GPL(wait_for_device_probe); 730 731/** 732 * driver_probe_device - attempt to bind device & driver together 733 * @drv: driver to bind a device to 734 * @dev: device to try to bind to the driver 735 * |
736 * This function returns -ENODEV if the device is not registered, 737 * 1 if the device is bound successfully and 0 otherwise. | 736 * This function returns -ENODEV if the device is not registered, -EBUSY if it 737 * already has a driver, and 1 if the device is bound successfully and 0 738 * otherwise. |
738 * 739 * This function must be called with @dev lock held. When called for a 740 * USB interface, @dev->parent lock must be held as well. 741 * 742 * If the device has a parent, runtime-resume the parent before driver probing. 743 */ 744static int driver_probe_device(struct device_driver *drv, struct device *dev) 745{ 746 int ret = 0; 747 | 739 * 740 * This function must be called with @dev lock held. When called for a 741 * USB interface, @dev->parent lock must be held as well. 742 * 743 * If the device has a parent, runtime-resume the parent before driver probing. 744 */ 745static int driver_probe_device(struct device_driver *drv, struct device *dev) 746{ 747 int ret = 0; 748 |
748 if (!device_is_registered(dev)) | 749 if (dev->p->dead || !device_is_registered(dev)) |
749 return -ENODEV; | 750 return -ENODEV; |
751 if (dev->driver) 752 return -EBUSY; |
|
750 751 dev->can_match = true; 752 pr_debug("bus: '%s': %s: matched device %s with driver %s\n", 753 drv->bus->name, __func__, dev_name(dev), drv->name); 754 755 pm_runtime_get_suppliers(dev); 756 if (dev->parent) 757 pm_runtime_get_sync(dev->parent); --- 264 unchanged lines hidden (view full) --- 1022 * @drv: Driver to attach 1023 * @dev: Device to attach it to 1024 * 1025 * Manually attach driver to a device. Will acquire both @dev lock and 1026 * @dev->parent lock if needed. 1027 */ 1028int device_driver_attach(struct device_driver *drv, struct device *dev) 1029{ | 753 754 dev->can_match = true; 755 pr_debug("bus: '%s': %s: matched device %s with driver %s\n", 756 drv->bus->name, __func__, dev_name(dev), drv->name); 757 758 pm_runtime_get_suppliers(dev); 759 if (dev->parent) 760 pm_runtime_get_sync(dev->parent); --- 264 unchanged lines hidden (view full) --- 1025 * @drv: Driver to attach 1026 * @dev: Device to attach it to 1027 * 1028 * Manually attach driver to a device. Will acquire both @dev lock and 1029 * @dev->parent lock if needed. 1030 */ 1031int device_driver_attach(struct device_driver *drv, struct device *dev) 1032{ |
1030 int ret = 0; | 1033 int ret; |
1031 1032 __device_driver_lock(dev, dev->parent); | 1034 1035 __device_driver_lock(dev, dev->parent); |
1033 1034 /* 1035 * If device has been removed or someone has already successfully 1036 * bound a driver before us just skip the driver probe call. 1037 */ 1038 if (!dev->p->dead && !dev->driver) 1039 ret = driver_probe_device(drv, dev); 1040 | 1036 ret = driver_probe_device(drv, dev); |
1041 __device_driver_unlock(dev, dev->parent); 1042 1043 return ret; 1044} 1045 1046static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie) 1047{ 1048 struct device *dev = _dev; 1049 struct device_driver *drv; | 1037 __device_driver_unlock(dev, dev->parent); 1038 1039 return ret; 1040} 1041 1042static void __driver_attach_async_helper(void *_dev, async_cookie_t cookie) 1043{ 1044 struct device *dev = _dev; 1045 struct device_driver *drv; |
1050 int ret = 0; | 1046 int ret; |
1051 1052 __device_driver_lock(dev, dev->parent); | 1047 1048 __device_driver_lock(dev, dev->parent); |
1053 | |
1054 drv = dev->p->async_driver; | 1049 drv = dev->p->async_driver; |
1055 1056 /* 1057 * If device has been removed or someone has already successfully 1058 * bound a driver before us just skip the driver probe call. 1059 */ 1060 if (!dev->p->dead && !dev->driver) 1061 ret = driver_probe_device(drv, dev); 1062 | 1050 ret = driver_probe_device(drv, dev); |
1063 __device_driver_unlock(dev, dev->parent); 1064 1065 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); 1066 1067 put_device(dev); 1068} 1069 1070static int __driver_attach(struct device *dev, void *data) --- 208 unchanged lines hidden --- | 1051 __device_driver_unlock(dev, dev->parent); 1052 1053 dev_dbg(dev, "driver %s async attach completed: %d\n", drv->name, ret); 1054 1055 put_device(dev); 1056} 1057 1058static int __driver_attach(struct device *dev, void *data) --- 208 unchanged lines hidden --- |