[PATCH 1/3] efi: earlycon: unmap framebuffer when the console is unregistered
From: Mikhail Rudenko
Date: Wed Nov 25 2026 - 12:04:02 EST
EFI earlycon currently unmaps its framebuffer at a late initcall only if
the boot console has already been unregistered. With keep_bootcon, the
console is still registered at that point, so the mapping is retained.
Move the unmap to the console exit callback. This ties the mapping's
lifetime to the console's lifetime and releases it after console writers
have stopped. Clear the saved console pointer on exit.
Signed-off-by: Mikhail Rudenko <xyzzy@xxxxxxxxxxxxxx>
---
drivers/firmware/efi/earlycon.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/firmware/efi/earlycon.c b/drivers/firmware/efi/earlycon.c
index 3d060d59968cf..3a6eaf5481f40 100644
--- a/drivers/firmware/efi/earlycon.c
+++ b/drivers/firmware/efi/earlycon.c
@@ -14,7 +14,7 @@
#include <asm/early_ioremap.h>
-static const struct console *earlycon_console __initdata;
+static struct console *earlycon_console;
static const struct font_desc *font;
static u16 cur_line_y, max_line_y;
static u32 efi_x_array[1024];
@@ -44,14 +44,15 @@ static int __init efi_earlycon_remap_fb(void)
}
early_initcall(efi_earlycon_remap_fb);
-static int __init efi_earlycon_unmap_fb(void)
+static int efi_earlycon_exit(struct console *con)
{
- /* unmap the bootconsole fb unless keep_bootcon left it registered */
- if (efi_fb && !console_is_registered(earlycon_console))
+ if (efi_fb) {
memunmap(efi_fb);
+ efi_fb = NULL;
+ }
+ WRITE_ONCE(earlycon_console, NULL);
return 0;
}
-late_initcall(efi_earlycon_unmap_fb);
static __ref void *efi_earlycon_map(unsigned long start, unsigned long len)
{
@@ -269,6 +270,7 @@ static int __init efi_earlycon_setup(struct earlycon_device *device,
efi_earlycon_scroll_up(si);
device->con->write = efi_earlycon_write;
+ device->con->exit = efi_earlycon_exit;
earlycon_console = device->con;
return 0;
}
--
2.56.1