aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_firmware.c
diff options
context:
space:
mode:
authorNavdeep Parhar <np@FreeBSD.org>2011-11-19 00:20:28 +0000
committerNavdeep Parhar <np@FreeBSD.org>2011-11-19 00:20:28 +0000
commit059d10c7b6cce81b63e298ab09ec68506d0e674b (patch)
treeca345b16f9acfe1fbf8b6144a019ed0a241abc5f /sys/kern/subr_firmware.c
parentdcf47c2ba5e9ffa9f7d5c8badeae4cd548d59d17 (diff)
downloadsrc-059d10c7b6cce81b63e298ab09ec68506d0e674b.tar.gz
src-059d10c7b6cce81b63e298ab09ec68506d0e674b.zip
Do not increment the parent firmware's reference count when any other
firmware image in the module is registered. Instead, do it when the other image is itself referenced. This allows a module with multiple firmware images to be automatically unloaded when none of the firmware images are in use. Discussed with: jhb@ (on -hackers)
Notes
Notes: svn path=/head/; revision=227689
Diffstat (limited to 'sys/kern/subr_firmware.c')
-rw-r--r--sys/kern/subr_firmware.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/sys/kern/subr_firmware.c b/sys/kern/subr_firmware.c
index 209f3a7eac56..9a1ec3f94c2e 100644
--- a/sys/kern/subr_firmware.c
+++ b/sys/kern/subr_firmware.c
@@ -198,10 +198,8 @@ firmware_register(const char *imagename, const void *data, size_t datasize,
frp->fw.data = data;
frp->fw.datasize = datasize;
frp->fw.version = version;
- if (parent != NULL) {
+ if (parent != NULL)
frp->parent = PRIV_FW(parent);
- frp->parent->refcnt++;
- }
mtx_unlock(&firmware_mtx);
if (bootverbose)
printf("firmware: '%s' version %u: %zu bytes loaded at %p\n",
@@ -235,8 +233,6 @@ firmware_unregister(const char *imagename)
} else {
linker_file_t x = fp->file; /* save value */
- if (fp->parent != NULL) /* release parent reference */
- fp->parent->refcnt--;
/*
* Clear the whole entry with bzero to make sure we
* do not forget anything. Then restore 'file' which is
@@ -341,6 +337,8 @@ firmware_get(const char *imagename)
return NULL;
}
found: /* common exit point on success */
+ if (fp->refcnt == 0 && fp->parent != NULL)
+ fp->parent->refcnt++;
fp->refcnt++;
mtx_unlock(&firmware_mtx);
return &fp->fw;
@@ -363,6 +361,8 @@ firmware_put(const struct firmware *p, int flags)
mtx_lock(&firmware_mtx);
fp->refcnt--;
if (fp->refcnt == 0) {
+ if (fp->parent != NULL)
+ fp->parent->refcnt--;
if (flags & FIRMWARE_UNLOAD)
fp->flags |= FW_UNLOAD;
if (fp->file)