svn commit: r362838 - stable/12/sys/kern

Mark Johnston markj at FreeBSD.org
Wed Jul 1 15:27:35 UTC 2020


Author: markj
Date: Wed Jul  1 15:27:34 2020
New Revision: 362838
URL: https://svnweb.freebsd.org/changeset/base/362838

Log:
  MFC r362789 (by gallatin):
  Fix a panic when unloading firmware

Modified:
  stable/12/sys/kern/subr_firmware.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/subr_firmware.c
==============================================================================
--- stable/12/sys/kern/subr_firmware.c	Wed Jul  1 15:17:45 2020	(r362837)
+++ stable/12/sys/kern/subr_firmware.c	Wed Jul  1 15:27:34 2020	(r362838)
@@ -394,14 +394,12 @@ EVENTHANDLER_DEFINE(mountroot, firmware_mountroot, NUL
 static void
 unloadentry(void *unused1, int unused2)
 {
-	struct priv_fw *fp, *tmp;
+	struct priv_fw *fp;
 	int err;
-	bool changed;
 
 	mtx_lock(&firmware_mtx);
-	changed = false;
 restart:
-	LIST_FOREACH_SAFE(fp, &firmware_table, link, tmp) {
+	LIST_FOREACH(fp, &firmware_table, link) {
 		if (fp->file == NULL || fp->refcnt != 0 ||
 		    (fp->flags & FW_UNLOAD) == 0)
 			continue;
@@ -412,7 +410,6 @@ restart:
 		 * 2. clear FW_UNLOAD so we don't try this entry again.
 		 * 3. release the lock while trying to unload the module.
 		 */
-		changed = true;
 		fp->flags &= ~FW_UNLOAD;	/* do not try again */
 
 		/*
@@ -422,9 +419,11 @@ restart:
 		mtx_unlock(&firmware_mtx);
 		err = linker_release_module(NULL, NULL, fp->file);
 		mtx_lock(&firmware_mtx);
-	}
-	if (changed) {
-		changed = false;
+
+		/*
+		 * When we dropped the lock, another thread could have
+		 * removed an element, so we must restart the scan.
+		 */
 		goto restart;
 	}
 	mtx_unlock(&firmware_mtx);


More information about the svn-src-stable-12 mailing list