[PATCH v2 07/10] efi: Refactor init_primary_display() helpers

Thomas Zimmermann
2025-11-24T16:52:03Z

Rework the kernel's init_primary_display() helpers to allow for later
support of additional config-table entries and EDID information. No
functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
arch/loongarch/kernel/efi.c | 22 +++++++++++-----------
drivers/firmware/efi/efi-init.c | 19 ++++++++++---------
2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/arch/loongarch/kernel/efi.c b/arch/loongarch/kernel/efi.c
index 638a392d2cd2..1ef38036e8ae 100644
--- a/arch/loongarch/kernel/efi.c
+++ b/arch/loongarch/kernel/efi.c
@@ -81,19 +81,19 @@ EXPORT_SYMBOL_GPL(sysfb_primary_display);

static void __init init_primary_display(void)
{
- struct screen_info *si;
-
- if (screen_info_table == EFI_INVALID_TABLE_ADDR)
- return;
-
- si = early_memremap(screen_info_table, sizeof(*si));
- if (!si) {
- pr_err("Could not map screen_info config table\n");
+ if (screen_info_table == EFI_INVALID_TABLE_ADDR) {
+ struct screen_info *si = early_memremap(screen_info_table, sizeof(*si));
+
+ if (!si) {
+ pr_err("Could not map screen_info config table\n");
+ return;
+ }
+ sysfb_primary_display.screen = *si;
+ memset(si, 0, sizeof(*si));
+ early_memunmap(si, sizeof(*si));
+ } else {
return;
}
- sysfb_primary_display.screen = *si;
- memset(si, 0, sizeof(*si));
- early_memunmap(si, sizeof(*si));

memblock_reserve(__screen_info_lfb_base(&sysfb_primary_display.screen),
sysfb_primary_display.screen.lfb_size);
diff --git a/drivers/firmware/efi/efi-init.c b/drivers/firmware/efi/efi-init.c
index d1d418a34407..ca697d485116 100644
--- a/drivers/firmware/efi/efi-init.c
+++ b/drivers/firmware/efi/efi-init.c
@@ -67,10 +67,9 @@ EXPORT_SYMBOL_GPL(sysfb_primary_display);

static void __init init_primary_display(void)
{
- struct screen_info *si;
-
if (screen_info_table != EFI_INVALID_TABLE_ADDR) {
- si = early_memremap(screen_info_table, sizeof(*si));
+ struct screen_info *si = early_memremap(screen_info_table, sizeof(*si));
+
if (!si) {
pr_err("Could not map screen_info config table\n");
return;
@@ -78,14 +77,16 @@ static void __init init_primary_display(void)
sysfb_primary_display.screen = *si;
memset(si, 0, sizeof(*si));
early_memunmap(si, sizeof(*si));
+ } else {
+ return;
+ }

- if (memblock_is_map_memory(sysfb_primary_display.screen.lfb_base))
- memblock_mark_nomap(sysfb_primary_display.screen.lfb_base,
- sysfb_primary_display.screen.lfb_size);
+ if (memblock_is_map_memory(sysfb_primary_display.screen.lfb_base))
+ memblock_mark_nomap(sysfb_primary_display.screen.lfb_base,
+ sysfb_primary_display.screen.lfb_size);

- if (IS_ENABLED(CONFIG_EFI_EARLYCON))
- efi_earlycon_reprobe();
- }
+ if (IS_ENABLED(CONFIG_EFI_EARLYCON))
+ efi_earlycon_reprobe();
}

static int __init uefi_init(u64 efi_system_table)
--
2.51.1