From owner-cvs-src@FreeBSD.ORG Mon Jun 12 12:41:10 2006 Return-Path: X-Original-To: cvs-src@freebsd.org Delivered-To: cvs-src@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0101D16A41F; Mon, 12 Jun 2006 12:41:10 +0000 (UTC) (envelope-from john@baldwin.cx) Received: from server.baldwin.cx (66-23-211-162.clients.speedfactory.net [66.23.211.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id 69E4543D4C; Mon, 12 Jun 2006 12:41:08 +0000 (GMT) (envelope-from john@baldwin.cx) Received: from osx.baldwin.cx (osx.baldwin.cx [192.168.0.15]) (authenticated bits=0) by server.baldwin.cx (8.13.4/8.13.4) with ESMTP id k5CCf7vU011957; Mon, 12 Jun 2006 08:41:07 -0400 (EDT) (envelope-from john@baldwin.cx) From: John Baldwin To: Ian Dowse Date: Mon, 12 Jun 2006 08:41:01 -0400 User-Agent: KMail/1.9.1 References: <200606101704.k5AH479k065331@repoman.freebsd.org> In-Reply-To: <200606101704.k5AH479k065331@repoman.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200606120841.02447.john@baldwin.cx> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [192.168.0.1]); Mon, 12 Jun 2006 08:41:07 -0400 (EDT) X-Virus-Scanned: ClamAV 0.87.1/1532/Sun Jun 11 18:57:47 2006 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-104.4 required=4.2 tests=ALL_TRUSTED,BAYES_00, USER_IN_WHITELIST autolearn=ham version=3.1.0 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on server.baldwin.cx Cc: cvs-src@freebsd.org, src-committers@freebsd.org, cvs-all@freebsd.org Subject: Re: cvs commit: src/sys/sys firmware.h src/sys/kern subr_firmware.c X-BeenThere: cvs-src@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: CVS commit messages for the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jun 2006 12:41:10 -0000 On Saturday 10 June 2006 13:04, Ian Dowse wrote: > iedowse 2006-06-10 17:04:07 UTC > > FreeBSD src repository > > Modified files: > sys/sys firmware.h > sys/kern subr_firmware.c > Log: > Keep firmware images on the list until they have been unregistered > with firmware_unregister(). Previously when the last driver reference > had been dropped we would clear the list entry under the assumption > that the firmware module was about to be unloaded, but this was not > true if the firmware image had been loaded manually with kldload. > > This makes it possible to manually kldload firmware images as a > workaround for drivers such as ipw that attempt to load firmware > while resuming after a suspend. > > Reviewed by: mlaier (an earlier version of the patch) I ran into additional problems with firmware(9) as well. One problem is that if you kldload a firmware blob, you can kldunload it even while it is in use(!) because the awk script doesn't include any error checking in the mod_event function it generates. I've patched the awk script to fix this and tested it. With this the kldunload of a firmware module that a driver currently has a reference to now fails: Index: fw_stub.awk =================================================================== RCS file: /usr/cvs/src/sys/tools/fw_stub.awk,v retrieving revision 1.2 diff -u -r1.2 fw_stub.awk --- fw_stub.awk 30 Jan 2006 16:32:08 -0000 1.2 +++ fw_stub.awk 2 Jun 2006 16:00:42 -0000 @@ -125,7 +125,8 @@ printc("\nstatic int\n"\ opt_m "_fw_modevent(module_t mod, int type, void *unused)\ {\ - struct firmware *fp;\ + struct firmware *fp, *parent;\ + int error;\ switch (type) {\ case MOD_LOAD:"); @@ -136,11 +137,7 @@ # '-', '.' and '/' are converted to '_' by ld/objcopy gsub(/-|\.|\//, "_", symb); - if (file_i == 0) - reg = "\t\tfp = "; - else - reg = "\t\t(void)"; - + reg = "\t\tfp = "; reg = reg "firmware_register(\"" short "\", _binary_" symb "_start , "; reg = reg "(size_t)(_binary_" symb "_end - _binary_" symb "_start), "; reg = reg version ", "; @@ -148,21 +145,37 @@ if (file_i == 0) reg = reg "NULL);"; else - reg = reg "fp);"; + reg = reg "parent);"; printc(reg); + + printc("\t\tif (fp == NULL)"); + printc("\t\t\tgoto fail_" file_i ";"); + if (file_i == 0) + printc("\t\tparent = fp;"); } -printc("\t\treturn (0);\ - case MOD_UNLOAD:"); +printc("\t\treturn (0);"); + +for (file_i = num_files - 1; file_i > 0; file_i--) { + printc("\tfail_" file_i ":") + printc("\t\t(void)firmware_unregister(\"" shortnames[file_i - 1] "\");"); +} + +printc("\tfail_0:"); +printc("\t\treturn (ENXIO);"); + +printc("\tcase MOD_UNLOAD:"); for (file_i = 1; file_i < num_files; file_i++) { - printc("\t\tfirmware_unregister(\"" shortnames[file_i] "\");"); + printc("\t\terror = firmware_unregister(\"" shortnames[file_i] "\");"); + printc("\t\tif (error)"); + printc("\t\t\treturn (error);"); } -printc("\t\tfirmware_unregister(\"" shortnames[0] "\");"); +printc("\t\terror = firmware_unregister(\"" shortnames[0] "\");"); -printc("\t\treturn (0);\ +printc("\t\treturn (error);\ }\ return (EINVAL);\ }\ -- John Baldwin