diff options
author | jhb <jhb@FreeBSD.org> | 2009-10-22 14:53:44 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2009-10-22 14:53:44 +0000 |
commit | e3088a4b83931beff3476dfaa5d471761e0d5219 (patch) | |
tree | cd3ade1441074049c4c87b115d5e7afb352a1ad8 /sys | |
parent | f7d845e3ac12005c7b4ebf43903ca8b62168eb42 (diff) | |
download | FreeBSD-src-e3088a4b83931beff3476dfaa5d471761e0d5219.zip FreeBSD-src-e3088a4b83931beff3476dfaa5d471761e0d5219.tar.gz |
Set the devclass_t pointer specified in the DRIVER_MODULE() macro
sooner so it is always valid when a driver's identify routine is
called. Previously, new-bus would attempt to create the devclass for
a newly loaded driver in two separate places, once in
devclass_add_driver(), and again after devclass_add_driver() returned
in driver_module_handler(). Only the second lookup attempted to set a
device class' parent and set the devclass_t pointer specified in the
DRIVER_MODULE() macro. However, by the time it was executed, the
driver was already added to existing instances of the parent driver at
which point in time the new driver's identify routine would have been
invoked. The fix is to merge the two attempts and only create the
devclass once in devclass_add_driver() including setting the
devclass_t pointer passed to DRIVER_MODULE() before the driver is
added to any existing bus devices.
Reported by: avg
Reviewed by: imp
MFC after: 2 weeks
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/subr_bus.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index e4d1f9b..0c97aa3 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -1049,9 +1049,10 @@ devclass_driver_added(devclass_t dc, driver_t *driver) * @param driver the driver to register */ static int -devclass_add_driver(devclass_t dc, driver_t *driver, int pass) +devclass_add_driver(devclass_t dc, driver_t *driver, int pass, devclass_t *dcp) { driverlink_t dl; + const char *parentname; PDEBUG(("%s", DRIVERNAME(driver))); @@ -1072,9 +1073,17 @@ devclass_add_driver(devclass_t dc, driver_t *driver, int pass) kobj_class_compile((kobj_class_t) driver); /* - * Make sure the devclass which the driver is implementing exists. + * If the driver has any base classes, make the + * devclass inherit from the devclass of the driver's + * first base class. This will allow the system to + * search for drivers in both devclasses for children + * of a device using this driver. */ - devclass_find_internal(driver->name, NULL, TRUE); + if (driver->baseclasses) + parentname = driver->baseclasses[0]->name; + else + parentname = NULL; + *dcp = devclass_find_internal(driver->name, parentname, TRUE); dl->driver = driver; TAILQ_INSERT_TAIL(&dc->drivers, dl, link); @@ -4157,27 +4166,8 @@ driver_module_handler(module_t mod, int what, void *arg) driver = dmd->dmd_driver; PDEBUG(("Loading module: driver %s on bus %s (pass %d)", DRIVERNAME(driver), dmd->dmd_busname, pass)); - error = devclass_add_driver(bus_devclass, driver, pass); - if (error) - break; - - /* - * If the driver has any base classes, make the - * devclass inherit from the devclass of the driver's - * first base class. This will allow the system to - * search for drivers in both devclasses for children - * of a device using this driver. - */ - if (driver->baseclasses) { - const char *parentname; - parentname = driver->baseclasses[0]->name; - *dmd->dmd_devclass = - devclass_find_internal(driver->name, - parentname, TRUE); - } else { - *dmd->dmd_devclass = - devclass_find_internal(driver->name, NULL, TRUE); - } + error = devclass_add_driver(bus_devclass, driver, pass, + dmd->dmd_devclass); break; case MOD_UNLOAD: |