summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/kern/device_if.m11
-rw-r--r--sys/kern/subr_bus.c18
-rw-r--r--sys/sys/bus.h1
3 files changed, 26 insertions, 4 deletions
diff --git a/sys/kern/device_if.m b/sys/kern/device_if.m
index eb720eb..edec42b 100644
--- a/sys/kern/device_if.m
+++ b/sys/kern/device_if.m
@@ -316,3 +316,14 @@ METHOD int resume {
METHOD int quiesce {
device_t dev;
} DEFAULT null_quiesce;
+
+/**
+ * @brief Free the device softc
+ *
+ * @param _dev device pointer
+ * @param _softc pointer to softc
+ */
+METHOD void free_softc {
+ device_t _dev;
+ void *_softc;
+} DEFAULT device_free_softc;
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index def1652..1356684 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -2406,8 +2406,8 @@ device_get_softc(device_t dev)
void
device_set_softc(device_t dev, void *softc)
{
- if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC))
- free(dev->softc, M_BUS_SC);
+ if (dev->softc != NULL && !(dev->flags & DF_EXTERNALSOFTC))
+ DEVICE_FREE_SOFTC(dev, dev->softc);
dev->softc = softc;
if (dev->softc)
dev->flags |= DF_EXTERNALSOFTC;
@@ -2604,8 +2604,8 @@ device_set_driver(device_t dev, driver_t *driver)
if (dev->driver == driver)
return (0);
- if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) {
- free(dev->softc, M_BUS_SC);
+ if (dev->softc != NULL && !(dev->flags & DF_EXTERNALSOFTC)) {
+ DEVICE_FREE_SOFTC(dev, dev->softc);
dev->softc = NULL;
}
device_set_desc(dev, NULL);
@@ -4797,3 +4797,13 @@ bus_free_resource(device_t dev, int type, struct resource *r)
return (0);
return (bus_release_resource(dev, type, rman_get_rid(r), r));
}
+
+/*
+ * The "dev" argument passed to "device_free_softc()" is allowed to be
+ * NULL, if the device freeing the soft is not available.
+ */
+void
+device_free_softc(device_t dev, void *softc)
+{
+ free(softc, M_BUS_SC);
+}
diff --git a/sys/sys/bus.h b/sys/sys/bus.h
index 1d6f37e..941819a 100644
--- a/sys/sys/bus.h
+++ b/sys/sys/bus.h
@@ -468,6 +468,7 @@ int device_set_unit(device_t dev, int unit); /* XXX DONT USE XXX */
int device_shutdown(device_t dev);
void device_unbusy(device_t dev);
void device_verbose(device_t dev);
+void device_free_softc(device_t dev, void *softc);
/*
* Access functions for devclass.
OpenPOWER on IntegriCloud