diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2026-06-20 12:20:38 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2026-06-20 18:16:37 +0000 |
| commit | 8edcb37dd0753dc7e50044d9ccf0e991392a3d84 (patch) | |
| tree | 76ec9e5524a3566ad08f74e8632aedd8a8bf1abc | |
| parent | 3a4e049c38143980e472b2926abde3c7549530c4 (diff) | |
efirt(9): carefully destroy efi_lock
efi_init() might return error after initializing the mutex, in which
case MOD_UNLOAD() is not processed, and the mutex is not destroyed.
Similarly, efi_uninit() skips any processing if efi_runtime was left as
NULL, leaving mutex not destroyed.
Initialize the mutex in MOD_LOAD case, and destroy in MOD_UNLOAD, also
handling errors.
Reviewed by: imp
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D57704
| -rw-r--r-- | sys/dev/efidev/efirt.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/sys/dev/efidev/efirt.c b/sys/dev/efidev/efirt.c index 2e9a917de1f0..590d98030741 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: |
