diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index c08d66b6f64f..531eaf9f6337 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -2804,6 +2804,27 @@ resource_list_print_type(struct resource_list *rl, const char *name, int type, return (retval); } +/** + * @brief Releases all the resources in a list. + * + * @param rl The resource list to purge. + * + * @returns nothing + */ +void +resource_list_purge(struct resource_list *rl) +{ + struct resource_list_entry *rle; + + STAILQ_FOREACH(rle, rl, link) { + if (rle->res) + bus_release_resource(rman_get_device(rle->res), + rle->type, rle->rid, rle->res); + STAILQ_REMOVE_HEAD(rl, link); + free(rle, M_BUS); + } +} + /** * @brief Helper function for implementing DEVICE_PROBE() * diff --git a/sys/sys/bus.h b/sys/sys/bus.h index 6a54a728fc87..b811b145a63a 100644 --- a/sys/sys/bus.h +++ b/sys/sys/bus.h @@ -227,6 +227,7 @@ struct resource * int resource_list_release(struct resource_list *rl, device_t bus, device_t child, int type, int rid, struct resource *res); +void resource_list_purge(struct resource_list *rl); int resource_list_print_type(struct resource_list *rl, const char *name, int type, const char *format);