Index: subr_autoconf.c =================================================================== RCS file: /cvs/src/sys/kern/subr_autoconf.c,v retrieving revision 1.85 diff -u -p -r1.85 subr_autoconf.c --- subr_autoconf.c 9 Feb 2015 12:37:18 -0000 1.85 +++ subr_autoconf.c 9 Feb 2015 12:58:16 -0000 @@ -51,6 +51,7 @@ #include #include #include +#include #include "hotplug.h" #include "mpath.h" @@ -80,6 +81,7 @@ struct matchinfo { int autoconf_verbose = AUTOCONF_VERBOSE; /* trace probe calls */ static void mapply(struct matchinfo *, struct cfdata *); +void device_free(void *); struct deferred_config { TAILQ_ENTRY(deferred_config) dc_queue; @@ -932,13 +934,31 @@ device_ref(struct device *dv) * * Context: process or interrupt */ +struct device_free_mem { + struct task task; + size_t size; +}; + void device_unref(struct device *dv) { + struct device_free_mem *mem; struct cfattach *ca; if (atomic_dec_int_nv(&dv->dv_ref) == 0) { ca = dv->dv_cfdata->cf_attach; - free(dv, M_DEVBUF, ca->ca_devsize); + + mem = (struct device_free_mem *)dv; + /* arc4random_buf? */ + task_set(&mem->task, device_free, mem); + task_add(systq, &mem->task); } +} + +void +device_free(void *memp) +{ + struct device_free_mem *mem = memp; + + free(mem, M_DEVBUF, mem->size); }