mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/4] x86/boot/compressed: Enable -Wunused and remove unused variables
@ 2026-11-09 12:48 Thorsten Blum
  2026-11-09 12:48 ` [PATCH v4 1/4] x86/boot/compressed: Remove unused variables in EFI helpers Thorsten Blum
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-11-09 12:48 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Nicolas Schier, Ard Biesheuvel,
	Lorenzo Stoakes (ARM), Jan Stancek, Mike Rapoport (Microsoft),
	Pratyush Yadav (Google),
	Tom Lendacky, Ryan Roberts, Andreas Larsson, Andrew Morton,
	Kevin Brodsky
  Cc: linux-kernel, Thorsten Blum

This series marks potentially unused variables and functions as
__maybe_unused and removes truly unused ones. Patch 4 enables -Wunused,
matching the W=0 kernel defaults. With WERROR=y, the warnings failed as
follows:

  arch/x86/boot/compressed/acpi.c:25:1: error: '__efi_get_rsdp_addr' defined but not used
  arch/x86/boot/compressed/acpi.c:29:6: error: unused variable 'ret'
  arch/x86/boot/compressed/acpi.c:57:15: error: unused variable 'nr_tables'
  arch/x86/boot/compressed/efi.c:64:16: error: unused variable 'et'
  arch/x86/boot/compressed/efi.c:136:6: error: unused variable 'ret'
  arch/x86/boot/compressed/kaslr.c:600:13: error: unused variable 'i'

Patch 2 also drops a redundant efi_get_system_table() call and uses the
existing efi_get_conf_table() error path.

Changes in v4:
- Add a newline to the log message in efi_get_system_table() (Jan)
- Make efi_get_system_table() static and update misc.h (Jan)
- v3: https://lore.kernel.org/r/20261109005528.3477-6-blum@kernel.org/

Changes in v3:
- Rebase patch 4/4
- v2: https://lore.kernel.org/r/20260624120300.590233-6-thorsten.blum@linux.dev/

Changes in v2:
- Fix a kernel test robot issue by marking __efi_get_rsdp_addr() as
  __maybe_unused: https://lore.kernel.org/r/202606240416.cXegPpiJ-lkp@intel.com/
- v1: https://lore.kernel.org/r/20260621144116.224010-6-thorsten.blum@linux.dev/

Thorsten Blum (4):
  x86/boot/compressed: Remove unused variables in EFI helpers
  x86/boot/compressed: Clean up EFI RSDP lookup in efi_get_rsdp_addr()
  x86/boot/compressed: Mark process_mem_region() index __maybe_unused
  x86/boot/compressed: Enable -Wunused

 arch/x86/boot/compressed/Makefile |  3 +++
 arch/x86/boot/compressed/acpi.c   | 18 ++++--------------
 arch/x86/boot/compressed/efi.c    | 21 +++++++--------------
 arch/x86/boot/compressed/kaslr.c  |  3 ++-
 arch/x86/boot/compressed/misc.h   |  6 ------
 5 files changed, 16 insertions(+), 35 deletions(-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 1/4] x86/boot/compressed: Remove unused variables in EFI helpers
  2026-11-09 12:48 [PATCH v4 0/4] x86/boot/compressed: Enable -Wunused and remove unused variables Thorsten Blum
@ 2026-11-09 12:48 ` Thorsten Blum
  2026-11-09 12:48 ` [PATCH v4 2/4] x86/boot/compressed: Clean up EFI RSDP lookup in efi_get_rsdp_addr() Thorsten Blum
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-11-09 12:48 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Nicolas Schier, Ard Biesheuvel,
	Lorenzo Stoakes (ARM), Jan Stancek, Mike Rapoport (Microsoft),
	Pratyush Yadav (Google),
	Tom Lendacky, Ryan Roberts, Andreas Larsson, Andrew Morton,
	Kevin Brodsky
  Cc: linux-kernel, Thorsten Blum

efi_get_system_table() declares an unused et variable, and
efi_get_conf_table() declares an unused ret variable - remove both.

get_kexec_setup_data() also takes an unused et argument. Drop the
argument and update the only caller in efi_get_conf_table().

Also simplify the no EFI system table case in efi_get_system_table() by
falling through to the existing return since sys_tbl_pa is already zero,
and add the missing newline to the debug log message.

Reviewed-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Nicolas Schier <n.schier@fritz.com>
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 arch/x86/boot/compressed/efi.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/arch/x86/boot/compressed/efi.c b/arch/x86/boot/compressed/efi.c
index f2e50f9758e6..f2d08e756e66 100644
--- a/arch/x86/boot/compressed/efi.c
+++ b/arch/x86/boot/compressed/efi.c
@@ -61,7 +61,6 @@ unsigned long efi_get_system_table(struct boot_params *bp)
 {
 	unsigned long sys_tbl_pa;
 	struct efi_info *ei;
-	enum efi_type et;
 
 	/* Get systab from boot params. */
 	ei = &bp->efi_info;
@@ -70,10 +69,8 @@ unsigned long efi_get_system_table(struct boot_params *bp)
 #else
 	sys_tbl_pa = ei->efi_systab;
 #endif
-	if (!sys_tbl_pa) {
-		debug_putstr("EFI system table not found.");
-		return 0;
-	}
+	if (!sys_tbl_pa)
+		debug_putstr("EFI system table not found.\n");
 
 	return sys_tbl_pa;
 }
@@ -84,11 +81,10 @@ unsigned long efi_get_system_table(struct boot_params *bp)
  * the initial physical address via a struct setup_data entry, which is
  * checked for here, along with some sanity checks.
  */
-static struct efi_setup_data *get_kexec_setup_data(struct boot_params *bp,
-						   enum efi_type et)
+static struct efi_setup_data *get_kexec_setup_data(struct boot_params *bp)
 {
-#ifdef CONFIG_X86_64
 	struct efi_setup_data *esd = NULL;
+#ifdef CONFIG_X86_64
 	struct setup_data *data;
 	u64 pa_data;
 
@@ -112,10 +108,8 @@ static struct efi_setup_data *get_kexec_setup_data(struct boot_params *bp,
 		debug_putstr("kexec EFI environment missing valid configuration table.\n");
 		return NULL;
 	}
-
-	return esd;
 #endif
-	return NULL;
+	return esd;
 }
 
 /**
@@ -133,7 +127,6 @@ int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
 {
 	unsigned long sys_tbl_pa;
 	enum efi_type et;
-	int ret;
 
 	if (!cfg_tbl_pa || !cfg_tbl_len)
 		return -EINVAL;
@@ -149,7 +142,7 @@ int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
 		struct efi_setup_data *esd;
 
 		/* kexec provides an alternative EFI conf table, check for it. */
-		esd = get_kexec_setup_data(bp, et);
+		esd = get_kexec_setup_data(bp);
 
 		*cfg_tbl_pa = esd ? esd->tables : stbl->tables;
 		*cfg_tbl_len = stbl->nr_tables;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 2/4] x86/boot/compressed: Clean up EFI RSDP lookup in efi_get_rsdp_addr()
  2026-11-09 12:48 [PATCH v4 0/4] x86/boot/compressed: Enable -Wunused and remove unused variables Thorsten Blum
  2026-11-09 12:48 ` [PATCH v4 1/4] x86/boot/compressed: Remove unused variables in EFI helpers Thorsten Blum
@ 2026-11-09 12:48 ` Thorsten Blum
  2026-11-09 12:48 ` [PATCH v4 3/4] x86/boot/compressed: Mark process_mem_region() index __maybe_unused Thorsten Blum
  2026-11-09 12:48 ` [PATCH v4 4/4] x86/boot/compressed: Enable -Wunused Thorsten Blum
  3 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-11-09 12:48 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Nicolas Schier, Ard Biesheuvel,
	Lorenzo Stoakes (ARM), Jan Stancek, Mike Rapoport (Microsoft),
	Pratyush Yadav (Google),
	Tom Lendacky, Ryan Roberts, Andreas Larsson, Andrew Morton,
	Kevin Brodsky, Thorsten Blum, David Hildenbrand
  Cc: linux-kernel

Mark __efi_get_rsdp_addr() as __maybe_unused and remove the unused ret
variable. In efi_get_rsdp_addr(), remove the unused nr_tables variable
and use the function return values directly in the conditions.

Since efi_get_conf_table() already calls efi_get_system_table(), drop
the redundant efi_get_system_table() call and keep a single error path.

Make efi_get_system_table() static now that it has no callers outside of
efi.c, and remove its declaration and stub from misc.h.

Reviewed-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Nicolas Schier <n.schier@fritz.com>
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 arch/x86/boot/compressed/acpi.c | 18 ++++--------------
 arch/x86/boot/compressed/efi.c  |  2 +-
 arch/x86/boot/compressed/misc.h |  6 ------
 3 files changed, 5 insertions(+), 21 deletions(-)

diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c
index aed27604c11f..5b2064b9c199 100644
--- a/arch/x86/boot/compressed/acpi.c
+++ b/arch/x86/boot/compressed/acpi.c
@@ -21,12 +21,11 @@
  */
 struct mem_vector immovable_mem[MAX_NUMNODES*2];
 
-static acpi_physical_address
+static acpi_physical_address __maybe_unused
 __efi_get_rsdp_addr(unsigned long cfg_tbl_pa, unsigned int cfg_tbl_len)
 {
 #ifdef CONFIG_EFI
 	unsigned long rsdp_addr;
-	int ret;
 
 	/*
 	 * Search EFI system tables for RSDP. Preferred is ACPI_20_TABLE_GUID to
@@ -53,21 +52,12 @@ static acpi_physical_address efi_get_rsdp_addr(void)
 #ifdef CONFIG_EFI
 	unsigned long cfg_tbl_pa = 0;
 	unsigned int cfg_tbl_len;
-	unsigned long systab_pa;
-	unsigned int nr_tables;
-	enum efi_type et;
-	int ret;
 
-	et = efi_get_type(boot_params_ptr);
-	if (et == EFI_TYPE_NONE)
+	if (efi_get_type(boot_params_ptr) == EFI_TYPE_NONE)
 		return 0;
 
-	systab_pa = efi_get_system_table(boot_params_ptr);
-	if (!systab_pa)
-		error("EFI support advertised, but unable to locate system table.");
-
-	ret = efi_get_conf_table(boot_params_ptr, &cfg_tbl_pa, &cfg_tbl_len);
-	if (ret || !cfg_tbl_pa)
+	if (efi_get_conf_table(boot_params_ptr, &cfg_tbl_pa, &cfg_tbl_len) ||
+	    !cfg_tbl_pa)
 		error("EFI config table not found.");
 
 	return __efi_get_rsdp_addr(cfg_tbl_pa, cfg_tbl_len);
diff --git a/arch/x86/boot/compressed/efi.c b/arch/x86/boot/compressed/efi.c
index f2d08e756e66..93dbf4abb79e 100644
--- a/arch/x86/boot/compressed/efi.c
+++ b/arch/x86/boot/compressed/efi.c
@@ -57,7 +57,7 @@ enum efi_type efi_get_type(struct boot_params *bp)
  *
  * Return: EFI system table address on success. On error, return 0.
  */
-unsigned long efi_get_system_table(struct boot_params *bp)
+static unsigned long efi_get_system_table(struct boot_params *bp)
 {
 	unsigned long sys_tbl_pa;
 	struct efi_info *ei;
diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
index 4f86c5903e03..8c9f3283c92e 100644
--- a/arch/x86/boot/compressed/misc.h
+++ b/arch/x86/boot/compressed/misc.h
@@ -212,7 +212,6 @@ enum efi_type {
 #ifdef CONFIG_EFI
 /* helpers for early EFI config table access */
 enum efi_type efi_get_type(struct boot_params *bp);
-unsigned long efi_get_system_table(struct boot_params *bp);
 int efi_get_conf_table(struct boot_params *bp, unsigned long *cfg_tbl_pa,
 		       unsigned int *cfg_tbl_len);
 unsigned long efi_find_vendor_table(struct boot_params *bp,
@@ -225,11 +224,6 @@ static inline enum efi_type efi_get_type(struct boot_params *bp)
 	return EFI_TYPE_NONE;
 }
 
-static inline unsigned long efi_get_system_table(struct boot_params *bp)
-{
-	return 0;
-}
-
 static inline int efi_get_conf_table(struct boot_params *bp,
 				     unsigned long *cfg_tbl_pa,
 				     unsigned int *cfg_tbl_len)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 3/4] x86/boot/compressed: Mark process_mem_region() index __maybe_unused
  2026-11-09 12:48 [PATCH v4 0/4] x86/boot/compressed: Enable -Wunused and remove unused variables Thorsten Blum
  2026-11-09 12:48 ` [PATCH v4 1/4] x86/boot/compressed: Remove unused variables in EFI helpers Thorsten Blum
  2026-11-09 12:48 ` [PATCH v4 2/4] x86/boot/compressed: Clean up EFI RSDP lookup in efi_get_rsdp_addr() Thorsten Blum
@ 2026-11-09 12:48 ` Thorsten Blum
  2026-11-09 12:48 ` [PATCH v4 4/4] x86/boot/compressed: Enable -Wunused Thorsten Blum
  3 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-11-09 12:48 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Nicolas Schier, Ard Biesheuvel,
	Lorenzo Stoakes (ARM), Jan Stancek, Mike Rapoport (Microsoft),
	Pratyush Yadav (Google),
	Tom Lendacky, Ryan Roberts, Andreas Larsson, Andrew Morton,
	Kevin Brodsky, Thorsten Blum
  Cc: linux-kernel

The local index variable i in process_mem_region() is unused when either
CONFIG_MEMORY_HOTREMOVE or CONFIG_ACPI is disabled.

Mark it __maybe_unused accordingly.

Reviewed-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Nicolas Schier <n.schier@fritz.com>
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 arch/x86/boot/compressed/kaslr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index 290153818d0f..6f95092fa97e 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -599,7 +599,8 @@ static bool process_mem_region(struct mem_vector *region,
 			       unsigned long minimum,
 			       unsigned long image_size)
 {
-	int i;
+	int i __maybe_unused;
+
 	/*
 	 * If no immovable memory found, or MEMORY_HOTREMOVE disabled,
 	 * use @region directly.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v4 4/4] x86/boot/compressed: Enable -Wunused
  2026-11-09 12:48 [PATCH v4 0/4] x86/boot/compressed: Enable -Wunused and remove unused variables Thorsten Blum
                   ` (2 preceding siblings ...)
  2026-11-09 12:48 ` [PATCH v4 3/4] x86/boot/compressed: Mark process_mem_region() index __maybe_unused Thorsten Blum
@ 2026-11-09 12:48 ` Thorsten Blum
  3 siblings, 0 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-11-09 12:48 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Nicolas Schier, Ard Biesheuvel,
	Lorenzo Stoakes (ARM), Jan Stancek, Mike Rapoport (Microsoft),
	Pratyush Yadav (Google),
	Tom Lendacky, Ryan Roberts, Andreas Larsson, Andrew Morton,
	Kevin Brodsky, Vitaly Kuznetsov
  Cc: linux-kernel, Thorsten Blum, Ingo Molnar

arch/x86/boot/compressed/Makefile resets KBUILD_CFLAGS for this
directory, but does not re-enable -Wunused. Therefore, unused variables
and static functions in arch/x86/boot/compressed/ currently do not emit
warnings.

Add -Wunused to warn about these, and -Wno-unused-but-set-variable as
well as -Wno-unused-const-variable to match the W=0 kernel defaults.

Reviewed-by: Jan Stancek <jstancek@redhat.com>
Reviewed-by: Nicolas Schier <n.schier@fritz.com>
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 arch/x86/boot/compressed/Makefile | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 680ad803cba7..3ff75bc2239b 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -29,6 +29,9 @@ KBUILD_CFLAGS += $(CC_FLAGS_DIALECT)
 KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
 KBUILD_CFLAGS += -fno-jump-tables
 KBUILD_CFLAGS += -Wundef
+KBUILD_CFLAGS += -Wunused
+KBUILD_CFLAGS += -Wno-unused-but-set-variable
+KBUILD_CFLAGS += -Wno-unused-const-variable
 KBUILD_CFLAGS += -DDISABLE_BRANCH_PROFILING
 cflags-$(CONFIG_X86_32) := -march=i386
 cflags-$(CONFIG_X86_64) := -mcmodel=small -mno-red-zone

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-09 12:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 12:48 [PATCH v4 0/4] x86/boot/compressed: Enable -Wunused and remove unused variables Thorsten Blum
2026-11-09 12:48 ` [PATCH v4 1/4] x86/boot/compressed: Remove unused variables in EFI helpers Thorsten Blum
2026-11-09 12:48 ` [PATCH v4 2/4] x86/boot/compressed: Clean up EFI RSDP lookup in efi_get_rsdp_addr() Thorsten Blum
2026-11-09 12:48 ` [PATCH v4 3/4] x86/boot/compressed: Mark process_mem_region() index __maybe_unused Thorsten Blum
2026-11-09 12:48 ` [PATCH v4 4/4] x86/boot/compressed: Enable -Wunused Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®