git: b94b53178039 - stable/15 - efirt(9): carefully destroy efi_lock

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 25 Jun 2026 00:50:53 UTC
The branch stable/15 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=b94b53178039c86da9acb597a9191d5e5db0f636

commit b94b53178039c86da9acb597a9191d5e5db0f636
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-06-20 12:20:38 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-06-25 00:50:22 +0000

    efirt(9): carefully destroy efi_lock
    
    (cherry picked from commit 8edcb37dd0753dc7e50044d9ccf0e991392a3d84)
---
 sys/dev/efidev/efirt.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sys/dev/efidev/efirt.c b/sys/dev/efidev/efirt.c
index d6a572720c37..52ccb5ca548b 100644
--- a/sys/dev/efidev/efirt.c
+++ b/sys/dev/efidev/efirt.c
@@ -29,7 +29,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
 #include "opt_acpi.h"
 
 #include <sys/param.h>
@@ -184,7 +183,6 @@ efi_init(void)
 	TUNABLE_INT_FETCH("efi.rt.disabled", &rt_disabled);
 	if (rt_disabled == 1)
 		return (0);
-	mtx_init(&efi_lock, "efi", NULL, MTX_DEF);
 
 	if (efi_systbl_phys == 0) {
 		if (bootverbose)
@@ -285,8 +283,6 @@ efi_uninit(void)
 	efi_systbl = NULL;
 	efi_cfgtbl = NULL;
 	efi_runtime = NULL;
-
-	mtx_destroy(&efi_lock);
 }
 
 static int
@@ -858,13 +854,19 @@ const struct efi_ops *active_efi_ops = &efi_ops;
 static int
 efirt_modevents(module_t m, int event, void *arg __unused)
 {
+	int error;
 
 	switch (event) {
 	case MOD_LOAD:
-		return (efi_init());
+		mtx_init(&efi_lock, "efi", NULL, MTX_DEF);
+		error = efi_init();
+		if (error != 0)
+			mtx_destroy(&efi_lock);
+		return (error);
 
 	case MOD_UNLOAD:
 		efi_uninit();
+		mtx_destroy(&efi_lock);
 		return (0);
 
 	case MOD_SHUTDOWN: