From owner-svn-src-stable@FreeBSD.ORG Thu Sep 13 18:47:25 2012 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id ED0C5106566C; Thu, 13 Sep 2012 18:47:24 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BE2058FC14; Thu, 13 Sep 2012 18:47:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q8DIlOJU053960; Thu, 13 Sep 2012 18:47:24 GMT (envelope-from np@svn.freebsd.org) Received: (from np@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q8DIlO6v053958; Thu, 13 Sep 2012 18:47:24 GMT (envelope-from np@svn.freebsd.org) Message-Id: <201209131847.q8DIlO6v053958@svn.freebsd.org> From: Navdeep Parhar Date: Thu, 13 Sep 2012 18:47:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r240472 - stable/9/sys/kern X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Sep 2012 18:47:25 -0000 Author: np Date: Thu Sep 13 18:47:24 2012 New Revision: 240472 URL: http://svn.freebsd.org/changeset/base/240472 Log: MFC r227689: 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. Modified: stable/9/sys/kern/subr_firmware.c Directory Properties: stable/9/sys/ (props changed) Modified: stable/9/sys/kern/subr_firmware.c ============================================================================== --- stable/9/sys/kern/subr_firmware.c Thu Sep 13 18:24:13 2012 (r240471) +++ stable/9/sys/kern/subr_firmware.c Thu Sep 13 18:47:24 2012 (r240472) @@ -198,10 +198,8 @@ firmware_register(const char *imagename, 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 *imagenam } 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, i 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)