Skip to content

Commit 07e4a3e

Browse files
mochel@digitalimplant.orggregkh
authored andcommitted
[PATCH] Move device/driver code to drivers/base/dd.c
This relocates the driver binding/unbinding code to drivers/base/dd.c. This is done for two reasons: One, it's not code related to the bus_type itself; it uses some from that, some from devices, and some from drivers. And Two, it will make it easier to do some of the upcoming lock removal on that code.. Signed-off-by: Patrick Mochel <mochel@digitalimplant.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent af70316 commit 07e4a3e

4 files changed

Lines changed: 203 additions & 183 deletions

File tree

‎drivers/base/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Makefile for the Linux device tree
22

3-
obj-y := core.o sys.o bus.o \
3+
obj-y := core.o sys.o bus.o dd.o \
44
driver.o class.o platform.o \
55
cpu.o firmware.o init.o map.o dmapool.o \
66
attribute_container.o transport_class.o

‎drivers/base/base.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ extern void bus_remove_device(struct device * dev);
44
extern int bus_add_driver(struct device_driver *);
55
extern void bus_remove_driver(struct device_driver *);
66

7+
extern void driver_detach(struct device_driver * drv);
8+
79
static inline struct class_device *to_class_dev(struct kobject *obj)
810
{
911
return container_of(obj, struct class_device, kobj);

‎drivers/base/bus.c‎

Lines changed: 0 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "power/power.h"
1919

2020
#define to_dev(node) container_of(node, struct device, bus_list)
21-
#define to_drv(node) container_of(node, struct device_driver, kobj.entry)
2221

2322
#define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr)
2423
#define to_bus(obj) container_of(obj, struct bus_type, subsys.kset.kobj)
@@ -243,181 +242,6 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start,
243242
return ret;
244243
}
245244

246-
/**
247-
* device_bind_driver - bind a driver to one device.
248-
* @dev: device.
249-
*
250-
* Allow manual attachment of a driver to a device.
251-
* Caller must have already set @dev->driver.
252-
*
253-
* Note that this does not modify the bus reference count
254-
* nor take the bus's rwsem. Please verify those are accounted
255-
* for before calling this. (It is ok to call with no other effort
256-
* from a driver's probe() method.)
257-
*/
258-
259-
void device_bind_driver(struct device * dev)
260-
{
261-
pr_debug("bound device '%s' to driver '%s'\n",
262-
dev->bus_id, dev->driver->name);
263-
list_add_tail(&dev->driver_list, &dev->driver->devices);
264-
sysfs_create_link(&dev->driver->kobj, &dev->kobj,
265-
kobject_name(&dev->kobj));
266-
sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver");
267-
}
268-
269-
270-
/**
271-
* driver_probe_device - attempt to bind device & driver.
272-
* @drv: driver.
273-
* @dev: device.
274-
*
275-
* First, we call the bus's match function, if one present, which
276-
* should compare the device IDs the driver supports with the
277-
* device IDs of the device. Note we don't do this ourselves
278-
* because we don't know the format of the ID structures, nor what
279-
* is to be considered a match and what is not.
280-
*
281-
* If we find a match, we call @drv->probe(@dev) if it exists, and
282-
* call device_bind_driver() above.
283-
*/
284-
int driver_probe_device(struct device_driver * drv, struct device * dev)
285-
{
286-
int error = 0;
287-
288-
if (drv->bus->match && !drv->bus->match(dev, drv))
289-
return -ENODEV;
290-
291-
down(&dev->sem);
292-
dev->driver = drv;
293-
if (drv->probe) {
294-
error = drv->probe(dev);
295-
if (error) {
296-
dev->driver = NULL;
297-
up(&dev->sem);
298-
return error;
299-
}
300-
}
301-
up(&dev->sem);
302-
device_bind_driver(dev);
303-
return 0;
304-
}
305-
306-
307-
/**
308-
* device_attach - try to attach device to a driver.
309-
* @dev: device.
310-
*
311-
* Walk the list of drivers that the bus has and call
312-
* driver_probe_device() for each pair. If a compatible
313-
* pair is found, break out and return.
314-
*/
315-
int device_attach(struct device * dev)
316-
{
317-
struct bus_type * bus = dev->bus;
318-
struct list_head * entry;
319-
int error;
320-
321-
if (dev->driver) {
322-
device_bind_driver(dev);
323-
return 1;
324-
}
325-
326-
if (bus->match) {
327-
list_for_each(entry, &bus->drivers.list) {
328-
struct device_driver * drv = to_drv(entry);
329-
error = driver_probe_device(drv, dev);
330-
if (!error)
331-
/* success, driver matched */
332-
return 1;
333-
if (error != -ENODEV && error != -ENXIO)
334-
/* driver matched but the probe failed */
335-
printk(KERN_WARNING
336-
"%s: probe of %s failed with error %d\n",
337-
drv->name, dev->bus_id, error);
338-
}
339-
}
340-
341-
return 0;
342-
}
343-
344-
345-
/**
346-
* driver_attach - try to bind driver to devices.
347-
* @drv: driver.
348-
*
349-
* Walk the list of devices that the bus has on it and try to
350-
* match the driver with each one. If driver_probe_device()
351-
* returns 0 and the @dev->driver is set, we've found a
352-
* compatible pair.
353-
*
354-
* Note that we ignore the -ENODEV error from driver_probe_device(),
355-
* since it's perfectly valid for a driver not to bind to any devices.
356-
*/
357-
void driver_attach(struct device_driver * drv)
358-
{
359-
struct bus_type * bus = drv->bus;
360-
struct list_head * entry;
361-
int error;
362-
363-
if (!bus->match)
364-
return;
365-
366-
list_for_each(entry, &bus->devices.list) {
367-
struct device * dev = container_of(entry, struct device, bus_list);
368-
if (!dev->driver) {
369-
error = driver_probe_device(drv, dev);
370-
if (error && (error != -ENODEV))
371-
/* driver matched but the probe failed */
372-
printk(KERN_WARNING
373-
"%s: probe of %s failed with error %d\n",
374-
drv->name, dev->bus_id, error);
375-
}
376-
}
377-
}
378-
379-
380-
/**
381-
* device_release_driver - manually detach device from driver.
382-
* @dev: device.
383-
*
384-
* Manually detach device from driver.
385-
* Note that this is called without incrementing the bus
386-
* reference count nor taking the bus's rwsem. Be sure that
387-
* those are accounted for before calling this function.
388-
*/
389-
390-
void device_release_driver(struct device * dev)
391-
{
392-
struct device_driver * drv;
393-
394-
down(&dev->sem);
395-
drv = dev->driver;
396-
if (drv) {
397-
sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
398-
sysfs_remove_link(&dev->kobj, "driver");
399-
list_del_init(&dev->driver_list);
400-
if (drv->remove)
401-
drv->remove(dev);
402-
dev->driver = NULL;
403-
}
404-
up(&dev->sem);
405-
}
406-
407-
408-
/**
409-
* driver_detach - detach driver from all devices it controls.
410-
* @drv: driver.
411-
*/
412-
413-
static void driver_detach(struct device_driver * drv)
414-
{
415-
while (!list_empty(&drv->devices)) {
416-
struct device * dev = container_of(drv->devices.next, struct device, driver_list);
417-
device_release_driver(dev);
418-
}
419-
}
420-
421245
static int device_add_attrs(struct bus_type * bus, struct device * dev)
422246
{
423247
int error = 0;
@@ -757,12 +581,6 @@ int __init buses_init(void)
757581
EXPORT_SYMBOL_GPL(bus_for_each_dev);
758582
EXPORT_SYMBOL_GPL(bus_for_each_drv);
759583

760-
EXPORT_SYMBOL_GPL(driver_probe_device);
761-
EXPORT_SYMBOL_GPL(device_bind_driver);
762-
EXPORT_SYMBOL_GPL(device_release_driver);
763-
EXPORT_SYMBOL_GPL(device_attach);
764-
EXPORT_SYMBOL_GPL(driver_attach);
765-
766584
EXPORT_SYMBOL_GPL(bus_add_device);
767585
EXPORT_SYMBOL_GPL(bus_remove_device);
768586
EXPORT_SYMBOL_GPL(bus_register);

0 commit comments

Comments
 (0)