From e34b12b9cdb507666a4eafdf2f1e52a113dcb791 Mon Sep 17 00:00:00 2001 From: imp Date: Tue, 14 Oct 2003 06:22:07 +0000 Subject: With DIAGNOSTICS, sometimes we get weird crashes when some driver accesses softc after it is freed. Use a different malloc type for softc than the rest of the bus code to make it more clear when these things happen that it is the driver that's at fault, not the bus code. Suggested by: sam and/or phk (I think) --- sys/kern/subr_bus.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'sys/kern/subr_bus.c') diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 7bb7704..03049bf 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -132,6 +132,7 @@ struct device_op_desc { }; static MALLOC_DEFINE(M_BUS, "bus", "Bus data structures"); +static MALLOC_DEFINE(M_BUS_SC, "bus-sc", "Bus data structures, softc"); #ifdef BUS_DEBUG @@ -1257,7 +1258,7 @@ void device_set_softc(device_t dev, void *softc) { if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) - free(dev->softc, M_BUS); + free(dev->softc, M_BUS_SC); dev->softc = softc; if (dev->softc) dev->flags |= DF_EXTERNALSOFTC; @@ -1396,7 +1397,7 @@ device_set_driver(device_t dev, driver_t *driver) return (0); if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) { - free(dev->softc, M_BUS); + free(dev->softc, M_BUS_SC); dev->softc = NULL; } kobj_delete((kobj_t) dev, 0); @@ -1404,7 +1405,7 @@ device_set_driver(device_t dev, driver_t *driver) if (driver) { kobj_init((kobj_t) dev, (kobj_class_t) driver); if (!(dev->flags & DF_EXTERNALSOFTC) && driver->size > 0) { - dev->softc = malloc(driver->size, M_BUS, + dev->softc = malloc(driver->size, M_BUS_SC, M_NOWAIT | M_ZERO); if (!dev->softc) { kobj_delete((kobj_t) dev, 0); -- cgit v1.1