dd.c (f0cd91a68acdc9b49d7f6738b514a426da627649) | dd.c (f86db396ff455ed586751d21816a1ebd431264e5) |
---|---|
1/* 2 * drivers/base/dd.c - The core device/driver interactions. 3 * 4 * This file contains the (sometimes tricky) code that controls the 5 * interactions between devices and drivers, which primarily includes 6 * driver binding and unbinding. 7 * 8 * All of this code used to exist in drivers/base/bus.c, but was --- 24 unchanged lines hidden (view full) --- 33 * 34 * Note that this does not modify the bus reference count 35 * nor take the bus's rwsem. Please verify those are accounted 36 * for before calling this. (It is ok to call with no other effort 37 * from a driver's probe() method.) 38 * 39 * This function must be called with @dev->sem held. 40 */ | 1/* 2 * drivers/base/dd.c - The core device/driver interactions. 3 * 4 * This file contains the (sometimes tricky) code that controls the 5 * interactions between devices and drivers, which primarily includes 6 * driver binding and unbinding. 7 * 8 * All of this code used to exist in drivers/base/bus.c, but was --- 24 unchanged lines hidden (view full) --- 33 * 34 * Note that this does not modify the bus reference count 35 * nor take the bus's rwsem. Please verify those are accounted 36 * for before calling this. (It is ok to call with no other effort 37 * from a driver's probe() method.) 38 * 39 * This function must be called with @dev->sem held. 40 */ |
41void device_bind_driver(struct device * dev) | 41int device_bind_driver(struct device *dev) |
42{ | 42{ |
43 if (klist_node_attached(&dev->knode_driver)) 44 return; | 43 int ret; |
45 | 44 |
45 if (klist_node_attached(&dev->knode_driver)) { 46 printk(KERN_WARNING "%s: device %s already bound\n", 47 __FUNCTION__, kobject_name(&dev->kobj)); 48 return 0; 49 } 50 |
|
46 pr_debug("bound device '%s' to driver '%s'\n", 47 dev->bus_id, dev->driver->name); 48 klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); | 51 pr_debug("bound device '%s' to driver '%s'\n", 52 dev->bus_id, dev->driver->name); 53 klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); |
49 sysfs_create_link(&dev->driver->kobj, &dev->kobj, | 54 ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, |
50 kobject_name(&dev->kobj)); | 55 kobject_name(&dev->kobj)); |
51 sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); | 56 if (ret == 0) { 57 ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj, 58 "driver"); 59 if (ret) 60 sysfs_remove_link(&dev->driver->kobj, 61 kobject_name(&dev->kobj)); 62 } 63 return ret; |
52} 53 54/** 55 * driver_probe_device - attempt to bind device & driver. 56 * @drv: driver. 57 * @dev: device. 58 * 59 * First, we call the bus's match function, if one present, which --- 26 unchanged lines hidden (view full) --- 86 } 87 } else if (drv->probe) { 88 ret = drv->probe(dev); 89 if (ret) { 90 dev->driver = NULL; 91 goto ProbeFailed; 92 } 93 } | 64} 65 66/** 67 * driver_probe_device - attempt to bind device & driver. 68 * @drv: driver. 69 * @dev: device. 70 * 71 * First, we call the bus's match function, if one present, which --- 26 unchanged lines hidden (view full) --- 98 } 99 } else if (drv->probe) { 100 ret = drv->probe(dev); 101 if (ret) { 102 dev->driver = NULL; 103 goto ProbeFailed; 104 } 105 } |
94 device_bind_driver(dev); | 106 if (device_bind_driver(dev)) { 107 printk(KERN_ERR "%s: device_bind_driver(%s) failed\n", 108 __FUNCTION__, dev->bus_id); 109 /* How does undo a ->probe? We're screwed. */ 110 } |
95 ret = 1; 96 pr_debug("%s: Bound Device %s to Driver %s\n", 97 drv->bus->name, dev->bus_id, drv->name); 98 goto Done; 99 100 ProbeFailed: 101 if (ret == -ENODEV || ret == -ENXIO) { 102 /* Driver matched, but didn't support device --- 31 unchanged lines hidden (view full) --- 134 * When called for a USB interface, @dev->parent->sem must be held. 135 */ 136int device_attach(struct device * dev) 137{ 138 int ret = 0; 139 140 down(&dev->sem); 141 if (dev->driver) { | 111 ret = 1; 112 pr_debug("%s: Bound Device %s to Driver %s\n", 113 drv->bus->name, dev->bus_id, drv->name); 114 goto Done; 115 116 ProbeFailed: 117 if (ret == -ENODEV || ret == -ENXIO) { 118 /* Driver matched, but didn't support device --- 31 unchanged lines hidden (view full) --- 150 * When called for a USB interface, @dev->parent->sem must be held. 151 */ 152int device_attach(struct device * dev) 153{ 154 int ret = 0; 155 156 down(&dev->sem); 157 if (dev->driver) { |
142 device_bind_driver(dev); 143 ret = 1; | 158 ret = device_bind_driver(dev); 159 if (ret == 0) 160 ret = 1; |
144 } else 145 ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); 146 up(&dev->sem); 147 return ret; 148} 149 150static int __driver_attach(struct device * dev, void * data) 151{ --- 25 unchanged lines hidden (view full) --- 177 * driver_attach - try to bind driver to devices. 178 * @drv: driver. 179 * 180 * Walk the list of devices that the bus has on it and try to 181 * match the driver with each one. If driver_probe_device() 182 * returns 0 and the @dev->driver is set, we've found a 183 * compatible pair. 184 */ | 161 } else 162 ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); 163 up(&dev->sem); 164 return ret; 165} 166 167static int __driver_attach(struct device * dev, void * data) 168{ --- 25 unchanged lines hidden (view full) --- 194 * driver_attach - try to bind driver to devices. 195 * @drv: driver. 196 * 197 * Walk the list of devices that the bus has on it and try to 198 * match the driver with each one. If driver_probe_device() 199 * returns 0 and the @dev->driver is set, we've found a 200 * compatible pair. 201 */ |
185void driver_attach(struct device_driver * drv) | 202int driver_attach(struct device_driver * drv) |
186{ | 203{ |
187 bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); | 204 return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); |
188} 189 190/** 191 * device_release_driver - manually detach device from driver. 192 * @dev: device. 193 * 194 * Manually detach device from driver. 195 * --- 75 unchanged lines hidden --- | 205} 206 207/** 208 * device_release_driver - manually detach device from driver. 209 * @dev: device. 210 * 211 * Manually detach device from driver. 212 * --- 75 unchanged lines hidden --- |