Skip to contentSkip to conversation

efi: fix -Wmissing-variable-declarations warning

PATCH In review Justin Stitt 2 participants 3 messages Aug 30, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 efi: fix -Wmissing-variable-declarations warning

When building x86/defconfig with Clang-18 I encounter the following warnings:

| arch/x86/platform/efi/efi.c:934:23: warning: no previous extern declaration for non-static variable 'efi_attr_fw_vendor' [-Wmissing-variable-declarations]
|   934 | struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor);
| arch/x86/platform/efi/efi.c:935:23: warning: no previous extern declaration for non-static variable 'efi_attr_runtime' [-Wmissing-variable-declarations]
|   935 | struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime);
| arch/x86/platform/efi/efi.c:936:23: warning: no previous extern declaration for non-static variable 'efi_attr_config_table' [-Wmissing-variable-declarations]
|   936 | struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table);

These symbols are declared extern in drivers/firmware/efi/efi.c. Move the declarations to linux/efi.h to resolve these warnings.

Also, trim a trailing space from efi_set_variable_t typedef.

---
Changes in v2:
- Don't use static. Instead move symbols to header file (thanks Ard)
- Remove duplicated warnings output from b4 (thanks Ard)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Note: build-tested.

Also, a question: Why does the compiler warn at all? The extern declarations _do_ exist as Ard points out [1].

[1]: https://lore.kernel.org/all/CAMj1kXE_xs+wWno4G4U+6CFCOwO7JWcmNv4et5=W=ZRrQatWnQ@mail.gmail.com/

---
 drivers/firmware/efi/efi.c | 3 ---
 include/linux/efi.h        | 6 +++++-
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/firmware/efi/efi.c +0 -3
index 1599f1176842..7b4e59ccf09e 100644
@@ -161,9 +161,6 @@ static ssize_t fw_platform_size_show(struct kobject *kobj,
 	return sprintf(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32);
 }
 
-extern __weak struct kobj_attribute efi_attr_fw_vendor;
-extern __weak struct kobj_attribute efi_attr_runtime;
-extern __weak struct kobj_attribute efi_attr_config_table;
 static struct kobj_attribute efi_attr_fw_platform_size =
 	__ATTR_RO(fw_platform_size);
 
include/linux/efi.h +5 -1
index ab088c662e88..32f7ca60b0e9 100644
@@ -287,7 +287,7 @@ typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor,
 					 unsigned long *data_size, void *data);
 typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
 					      efi_guid_t *vendor);
-typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor, 
+typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
 					 u32 attr, unsigned long data_size,
 					 void *data);
 typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
@@ -632,6 +632,10 @@ typedef struct {
 
 extern unsigned long __ro_after_init efi_rng_seed;		/* RNG Seed table */
 
+extern __weak struct kobj_attribute efi_attr_fw_vendor;
+extern __weak struct kobj_attribute efi_attr_runtime;
+extern __weak struct kobj_attribute efi_attr_config_table;
+
 /*
  * All runtime access to EFI goes through this structure:
  */

---
base-commit: 706a741595047797872e669b3101429ab8d378ef
change-id: 20230829-missingvardecl-efi-59306aacfed4

Best regards,
--
Justin Stitt <[email protected]>

maintainer
#1 lore raw
Quoted 9 lines · Justin Stitt

When building x86/defconfig with Clang-18 I encounter the following warnings:

| arch/x86/platform/efi/efi.c:934:23: warning: no previous extern declaration for non-static variable 'efi_attr_fw_vendor' [-Wmissing-variable-declarations]
|   934 | struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor);
| arch/x86/platform/efi/efi.c:935:23: warning: no previous extern declaration for non-static variable 'efi_attr_runtime' [-Wmissing-variable-declarations]
|   935 | struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime);
| arch/x86/platform/efi/efi.c:936:23: warning: no previous extern declaration for non-static variable 'efi_attr_config_table' [-Wmissing-variable-declarations]
|   936 | struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table);
Quoted 8 lines

These symbols are declared extern in drivers/firmware/efi/efi.c. Move the declarations to linux/efi.h to resolve these warnings.

Also, trim a trailing space from efi_set_variable_t typedef.

Thanks, I'll take this as a fix.

Quoted 8 lines

---
Changes in v2:
- Don't use static. Instead move symbols to header file (thanks Ard)
- Remove duplicated warnings output from b4 (thanks Ard)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Note: build-tested.

Quoted 4 lines

Also, a question: Why does the compiler warn at all? The extern declarations _do_ exist as Ard points out [1].

[1]: https://lore.kernel.org/all/CAMj1kXE_xs+wWno4G4U+6CFCOwO7JWcmNv4et5=W=ZRrQatWnQ@mail.gmail.com/

Those declarations are not observed by the compiler when building .c files other than drivers/firmware/efi/efi.c, so they essentially don't exist when compiling arch/x86/platform/efi/efi.c.

Quoted 52 lines
---
 drivers/firmware/efi/efi.c | 3 ---
 include/linux/efi.h        | 6 +++++-
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/firmware/efi/efi.c +0 -3
index 1599f1176842..7b4e59ccf09e 100644
@@ -161,9 +161,6 @@ static ssize_t fw_platform_size_show(struct kobject *kobj,
        return sprintf(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32);
 }
 
-extern __weak struct kobj_attribute efi_attr_fw_vendor;
-extern __weak struct kobj_attribute efi_attr_runtime;
-extern __weak struct kobj_attribute efi_attr_config_table;
 static struct kobj_attribute efi_attr_fw_platform_size =
        __ATTR_RO(fw_platform_size);
 
include/linux/efi.h +5 -2
index ab088c662e88..32f7ca60b0e9 100644
@@ -287,7 +287,7 @@ typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor,
                                         unsigned long *data_size, void *data);
 typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
                                              efi_guid_t *vendor);
-typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
+typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
                                         u32 attr, unsigned long data_size,
                                         void *data);
 typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
@@ -632,6 +632,10 @@ typedef struct {
 
 extern unsigned long __ro_after_init efi_rng_seed;             /* RNG Seed table */
 
+extern __weak struct kobj_attribute efi_attr_fw_vendor;
+extern __weak struct kobj_attribute efi_attr_runtime;
+extern __weak struct kobj_attribute efi_attr_config_table;
+
 /*
  * All runtime access to EFI goes through this structure:
  */
 
---

base-commit: 706a741595047797872e669b3101429ab8d378ef
change-id: 20230829-missingvardecl-efi-59306aacfed4

Best regards,
--
Justin Stitt <[email protected]>

#2 lore raw
Quoted 30 lines · Ard Biesheuvel
Quoted 9 lines · Justin Stitt

When building x86/defconfig with Clang-18 I encounter the following warnings:

| arch/x86/platform/efi/efi.c:934:23: warning: no previous extern declaration for non-static variable 'efi_attr_fw_vendor' [-Wmissing-variable-declarations]
|   934 | struct kobj_attribute efi_attr_fw_vendor = __ATTR_RO(fw_vendor);
| arch/x86/platform/efi/efi.c:935:23: warning: no previous extern declaration for non-static variable 'efi_attr_runtime' [-Wmissing-variable-declarations]
|   935 | struct kobj_attribute efi_attr_runtime = __ATTR_RO(runtime);
| arch/x86/platform/efi/efi.c:936:23: warning: no previous extern declaration for non-static variable 'efi_attr_config_table' [-Wmissing-variable-declarations]
|   936 | struct kobj_attribute efi_attr_config_table = __ATTR_RO(config_table);
Quoted 8 lines

These symbols are declared extern in drivers/firmware/efi/efi.c. Move the declarations to linux/efi.h to resolve these warnings.

Also, trim a trailing space from efi_set_variable_t typedef.

Thanks, I'll take this as a fix.

Quoted 8 lines

---
Changes in v2:
- Don't use static. Instead move symbols to header file (thanks Ard)
- Remove duplicated warnings output from b4 (thanks Ard)
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Note: build-tested.

Quoted 8 lines
Quoted 4 lines

Also, a question: Why does the compiler warn at all? The extern declarations _do_ exist as Ard points out [1].

[1]: https://lore.kernel.org/all/CAMj1kXE_xs+wWno4G4U+6CFCOwO7JWcmNv4et5=W=ZRrQatWnQ@mail.gmail.com/

Those declarations are not observed by the compiler when building .c files other than drivers/firmware/efi/efi.c, so they essentially don't exist when compiling arch/x86/platform/efi/efi.c.

I see, the linker is resolving these later then?

Quoted 54 lines
Quoted 54 lines

---
 drivers/firmware/efi/efi.c | 3 ---
 include/linux/efi.h        | 6 +++++-
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/firmware/efi/efi.c +0 -3
index 1599f1176842..7b4e59ccf09e 100644
@@ -161,9 +161,6 @@ static ssize_t fw_platform_size_show(struct kobject *kobj,
        return sprintf(buf, "%d\n", efi_enabled(EFI_64BIT) ? 64 : 32);
 }
 
-extern __weak struct kobj_attribute efi_attr_fw_vendor;
-extern __weak struct kobj_attribute efi_attr_runtime;
-extern __weak struct kobj_attribute efi_attr_config_table;
 static struct kobj_attribute efi_attr_fw_platform_size =
        __ATTR_RO(fw_platform_size);
 
include/linux/efi.h +5 -2
index ab088c662e88..32f7ca60b0e9 100644
@@ -287,7 +287,7 @@ typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor,
                                         unsigned long *data_size, void *data);
 typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name,
                                              efi_guid_t *vendor);
-typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
+typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor,
                                         u32 attr, unsigned long data_size,
                                         void *data);
 typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count);
@@ -632,6 +632,10 @@ typedef struct {
 
 extern unsigned long __ro_after_init efi_rng_seed;             /* RNG Seed table */
 
+extern __weak struct kobj_attribute efi_attr_fw_vendor;
+extern __weak struct kobj_attribute efi_attr_runtime;
+extern __weak struct kobj_attribute efi_attr_config_table;
+
 /*
  * All runtime access to EFI goes through this structure:
  */
 
---

base-commit: 706a741595047797872e669b3101429ab8d378ef
change-id: 20230829-missingvardecl-efi-59306aacfed4

Best regards,
--
Justin Stitt <[email protected]>