summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_bus.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2000-07-03 13:06:29 +0000
committerphk <phk@FreeBSD.org>2000-07-03 13:06:29 +0000
commit32127fca4e7017d38be85bfd3630d6fb5abbcf2c (patch)
tree75a188ef3b35d65dc8974594d96e4ff5bd8b20e7 /sys/kern/subr_bus.c
parent4d4c1623e80b77960d7fa71960641b1c23c246f2 (diff)
downloadFreeBSD-src-32127fca4e7017d38be85bfd3630d6fb5abbcf2c.zip
FreeBSD-src-32127fca4e7017d38be85bfd3630d6fb5abbcf2c.tar.gz
Add device_set_softc() which does the obvious.
Not objected to by: dfr
Diffstat (limited to 'sys/kern/subr_bus.c')
-rw-r--r--sys/kern/subr_bus.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index ec91ca9..7b66e2e 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -855,6 +855,18 @@ device_get_softc(device_t dev)
return dev->softc;
}
+void
+device_set_softc(device_t dev, void *softc)
+{
+ if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC))
+ free(dev->softc, M_BUS);
+ dev->softc = softc;
+ if (dev->softc)
+ dev->flags |= DF_EXTERNALSOFTC;
+ else
+ dev->flags &= ~DF_EXTERNALSOFTC;
+}
+
void *
device_get_ivars(device_t dev)
{
@@ -976,7 +988,7 @@ device_set_driver(device_t dev, driver_t *driver)
if (dev->driver == driver)
return 0;
- if (dev->softc) {
+ if (dev->softc && !(dev->flags & DF_EXTERNALSOFTC)) {
free(dev->softc, M_BUS);
dev->softc = NULL;
}
@@ -984,13 +996,15 @@ device_set_driver(device_t dev, driver_t *driver)
dev->driver = driver;
if (driver) {
kobj_init((kobj_t) dev, (kobj_class_t) driver);
- dev->softc = malloc(driver->size, M_BUS, M_NOWAIT);
- if (!dev->softc) {
- kobj_init((kobj_t) dev, &null_class);
- dev->driver = NULL;
- return ENOMEM;
+ if (!(dev->flags & DF_EXTERNALSOFTC)) {
+ dev->softc = malloc(driver->size, M_BUS, M_NOWAIT);
+ if (!dev->softc) {
+ kobj_init((kobj_t) dev, &null_class);
+ dev->driver = NULL;
+ return ENOMEM;
+ }
+ bzero(dev->softc, driver->size);
}
- bzero(dev->softc, driver->size);
} else
kobj_init((kobj_t) dev, &null_class);
return 0;
OpenPOWER on IntegriCloud