From 039294682d6a32455623da81076597a6f8da39b3 Mon Sep 17 00:00:00 2001 From: Patrick Mochel Date: Thu, 19 Dec 2002 03:46:29 -0600 Subject: kobjects: minor updates - check if subsystem is NULL during subsys_get(). - Don't increment parent's reference count before we check if we have a valid kobject during kobject_add() - Do kobject_add() in subsys_register(), instead of kobject_register(), since we've already done kobject_init(). --- include/linux/kobject.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/linux') diff --git a/include/linux/kobject.h b/include/linux/kobject.h index 6b528c5a61cb..821d17e15a01 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -52,7 +52,7 @@ extern void subsystem_unregister(struct subsystem *); static inline struct subsystem * subsys_get(struct subsystem * s) { - return container_of(kobject_get(&s->kobj),struct subsystem,kobj); + return s ? container_of(kobject_get(&s->kobj),struct subsystem,kobj) : NULL; } static inline void subsys_put(struct subsystem * s) -- cgit v1.2.3 From c3a72b427ba8614b02268a82a9f04b7eb0ae57f0 Mon Sep 17 00:00:00 2001 From: Patrick Mochel Date: Thu, 19 Dec 2002 22:14:38 -0600 Subject: driver model: eliminate struct device_driver::bus_list - use list in embedded kobject instead. - remove struct bus_list::drivers; use ::drvsubsys. --- drivers/base/bus.c | 16 ++++++---------- include/linux/device.h | 2 -- 2 files changed, 6 insertions(+), 12 deletions(-) (limited to 'include/linux') diff --git a/drivers/base/bus.c b/drivers/base/bus.c index ca5ef19aa4a9..4cd3e9e002a4 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -19,7 +19,7 @@ static DECLARE_MUTEX(bus_sem); #define to_dev(node) container_of(node,struct device,bus_list) -#define to_drv(node) container_of(node,struct device_driver,bus_list) +#define to_drv(node) container_of(node,struct device_driver,kobj.entry) #define to_bus_attr(_attr) container_of(_attr,struct bus_attribute,attr) #define to_bus(obj) container_of(obj,struct bus_type,subsys.kobj) @@ -203,9 +203,9 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, if(!(bus = get_bus(bus))) return -EINVAL; - head = start ? &start->bus_list : &bus->drivers; + head = start ? &start->kobj.entry : &bus->drvsubsys.list; - down_read(&bus->subsys.rwsem); + down_read(&bus->drvsubsys.rwsem); list_for_each(entry,head) { struct device_driver * drv = get_driver(to_drv(entry)); error = fn(drv,data); @@ -213,7 +213,7 @@ int bus_for_each_drv(struct bus_type * bus, struct device_driver * start, if(error) break; } - up_read(&bus->subsys.rwsem); + up_read(&bus->drvsubsys.rwsem); return error; } @@ -287,9 +287,8 @@ static int device_attach(struct device * dev) if (!bus->match) return 0; - list_for_each(entry,&bus->drivers) { - struct device_driver * drv = - container_of(entry,struct device_driver,bus_list); + list_for_each(entry,&bus->drvsubsys.list) { + struct device_driver * drv = to_drv(entry); if (!(error = bus_match(dev,drv))) break; } @@ -437,7 +436,6 @@ int bus_add_driver(struct device_driver * drv) kobject_register(&drv->kobj); devclass_add_driver(drv); - list_add_tail(&drv->bus_list,&bus->drivers); driver_attach(drv); up_write(&bus->subsys.rwsem); } @@ -460,7 +458,6 @@ void bus_remove_driver(struct device_driver * drv) down_write(&drv->bus->subsys.rwsem); pr_debug("bus %s: remove driver %s\n",drv->bus->name,drv->name); driver_detach(drv); - list_del_init(&drv->bus_list); devclass_remove_driver(drv); kobject_unregister(&drv->kobj); up_write(&drv->bus->subsys.rwsem); @@ -491,7 +488,6 @@ void put_bus(struct bus_type * bus) int bus_register(struct bus_type * bus) { INIT_LIST_HEAD(&bus->devices); - INIT_LIST_HEAD(&bus->drivers); down(&bus_sem); strncpy(bus->subsys.kobj.name,bus->name,KOBJ_NAME_LEN); diff --git a/include/linux/device.h b/include/linux/device.h index 48612267bd65..0099e27316b0 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -69,7 +69,6 @@ struct bus_type { struct subsystem drvsubsys; struct subsystem devsubsys; struct list_head devices; - struct list_head drivers; int (*match)(struct device * dev, struct device_driver * drv); struct device * (*add) (struct device * parent, char * bus_id); @@ -119,7 +118,6 @@ struct device_driver { struct semaphore unload_sem; struct kobject kobj; - struct list_head bus_list; struct list_head class_list; struct list_head devices; -- cgit v1.2.3