Skip to contentSkip to conversation

x86/boot/compressed: Enable -Wunused and remove unused variables

PATCH Superseded Thorsten Blum 1 participant 5 messages Jun 21 x86

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover x86/boot/compressed: Enable -Wunused and remove unused variables

This series removes unused variables and enables -Wunused, matching the W=0 kernel defaults. With WERROR=y, the warnings failed as follows:

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'

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

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   | 16 +++-------------
 arch/x86/boot/compressed/efi.c    | 17 +++++------------
 arch/x86/boot/compressed/kaslr.c  |  3 ++-
 4 files changed, 13 insertions(+), 26 deletions(-)

base-commit: 1a3746ccbb0a97bed3c06ccde6b880013b1dddc1

#1 lore raw

PATCH 1/4 x86/boot/compressed: Remove unused variables in EFI helpers

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

get_kexec_setup_data() also takes an efi_type argument that is not used. 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.

---
 arch/x86/boot/compressed/efi.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
arch/x86/boot/compressed/efi.c +5 -12
index f2e50f9758e6..e0329a03618a 100644
@@ -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) {
+	if (!sys_tbl_pa)
 		debug_putstr("EFI system table not found.");
-		return 0;
-	}
 
 	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;
#2 lore raw

PATCH 2/4 x86/boot/compressed: Clean up EFI RSDP lookup in efi_get_rsdp_addr()

In reply to Thorsten Blum

Remove the unused ret variable in __efi_get_rsdp_addr() and the unused nr_tables variable in efi_get_rsdp_addr(). Also inline variables that are only used for simple if checks.

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.

---
 arch/x86/boot/compressed/acpi.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
arch/x86/boot/compressed/acpi.c +3 -13
index f196b1d1ddf8..92c239d8f40b 100644
@@ -26,7 +26,6 @@ __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);
#3 lore raw

PATCH 3/4 x86/boot/compressed: Mark process_mem_region() index __maybe_unused

In reply to Thorsten Blum

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.

---
 arch/x86/boot/compressed/kaslr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/boot/compressed/kaslr.c +2 -1
index 9fb1d495c688..1d06d4bdaec4 100644
@@ -593,7 +593,8 @@ static bool process_mem_region(struct mem_vector *region,
 			       unsigned long minimum,
 			       unsigned long image_size)
 {
-	int i;
+	int __maybe_unused i;
+
 	/*
 	 * If no immovable memory found, or MEMORY_HOTREMOVE disabled,
 	 * use @region directly.
#4 lore raw

PATCH 4/4 x86/boot/compressed: Enable -Wunused

In reply to Thorsten Blum

arch/x86/boot/compressed/Makefile resets the 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.

---
 arch/x86/boot/compressed/Makefile | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/boot/compressed/Makefile +3 -0
index 07e0e64b9a98..c1315a7b712c 100644
@@ -28,6 +28,9 @@ KBUILD_CFLAGS := -m$(BITS) -O2 $(CLANG_FLAGS)
 KBUILD_CFLAGS += $(CC_FLAGS_DIALECT)
 KBUILD_CFLAGS += -fno-strict-aliasing -fPIE
 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