efi: fix -Wmissing-variable-declarations warning
Subsystems (3)
PATCH 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 variables are not externally declared anywhere (AFAIK) so let's add the static keyword and ensure we follow the ODR.
---
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); --- Note: build-tested. --- arch/x86/platform/efi/efi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/platform/efi/efi.c +3 -3
@@ -931,9 +931,9 @@ EFI_ATTR_SHOW(fw_vendor);EFI_ATTR_SHOW (runtime);EFI_ATTR_SHOW (config_table); -struct kobj_attribute efi_attr_fw_vendor =__ATTR_RO (fw_vendor); -struct kobj_attribute efi_attr_runtime =__ATTR_RO (runtime); -struct kobj_attribute efi_attr_config_table =__ATTR_RO (config_table); +static struct kobj_attribute efi_attr_fw_vendor =__ATTR_RO (fw_vendor); +static struct kobj_attribute efi_attr_runtime =__ATTR_RO (runtime); +static struct kobj_attribute efi_attr_config_table =__ATTR_RO (config_table);umode_t efi_attr_is_visible (struct kobject *kobj,struct attribute *attr,int n) {
---
base-commit: 706a741595047797872e669b3101429ab8d378ef
change-id: 20230829-missingvardecl-efi-59306aacfed4
Best regards,
--
Justin Stitt <[email protected]>
Ard Biesheuvel
maintainerHi Justin,
Quoted 10 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);These variables are not externally declared anywhere (AFAIK)
They are:
drivers/firmware/efi/efi.c:extern __weak struct kobj_attribute efi_attr_fw_vendor;
drivers/firmware/efi/efi.c:extern __weak struct kobj_attribute efi_attr_runtime; drivers/firmware/efi/efi.c:extern __weak struct kobj_attribute efi_attr_config_table;
Quoted 3 lines
so let's
add the static keyword and ensure we follow the ODR.
One Definition Rule, right? Better to spell that out.
Quoted 10 lines
Signed-off-by Justin Stitt <[email protected]>---
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);
This is duplicated. Is this a b4 fail?
Quoted 14 lines
---
Note: build-tested.--- arch/x86/platform/efi/efi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)arch/x86/platform/efi/efi.c +0
-0@@ -931,9 +931,9 @@ EFI_ATTR_SHOW(fw_vendor);EFI_ATTR_SHOW (runtime);EFI_ATTR_SHOW (config_table);
arch/x86/platform/efi/efi.c EFI_ATTR_SHOW(fw_vendor); · line 939
Quoted 10 lines
arch/x86/platform/efi/efi.c +3
-3-struct kobj_attribute efi_attr_fw_vendor =__ATTR_RO (fw_vendor); -struct kobj_attribute efi_attr_runtime =__ATTR_RO (runtime); -struct kobj_attribute efi_attr_config_table =__ATTR_RO (config_table); +static struct kobj_attribute efi_attr_fw_vendor =__ATTR_RO (fw_vendor); +static struct kobj_attribute efi_attr_runtime =__ATTR_RO (runtime); +static struct kobj_attribute efi_attr_config_table =__ATTR_RO (config_table);umode_t efi_attr_is_visible (struct kobject *kobj,struct attribute *attr,int n) {
This won't work.
Those variables are referenced via weak references in generic code. The idea is that the weak references resolve to NULL pointers on architectures other than x86, terminating the array early and hiding the non-existent variables.
Making them static in arch/x86/platform/efi/efi.c means that these references will remain unsatisfied, and so the variables will no longer be exposed on x86 either.
Quoted 1 line · Ard Biesheuvel
On Wed, 30 Aug 2023 at 00:54, Justin Stitt <[email protected]> wrote:
...
Quoted 22 lines
Quoted 9 lines
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 variables are not externally declared anywhere (AFAIK)
They are:
drivers/firmware/efi/efi.c:extern
__weakstructkobj_attributeefi_attr_fw_vendor;
drivers/firmware/efi/efi.c:extern__weakstructkobj_attributeefi_attr_runtime; drivers/firmware/efi/efi.c:extern__weakstructkobj_attributeefi_attr_config_table;Quoted 1 line
so let's add the static keyword and ensure we follow the ODR.
This won't work.
Quoted 8 lines
Those variables are referenced via weak references in generic code. The idea is that the weak references resolve to NULL pointers on architectures other than x86, terminating the array early and hiding the non-existent variables.
Making them static in
arch/x86/platform/efi/efi.cmeans that these references will remain unsatisfied, and so the variables will no longer be exposed on x86 either.
So it means that we have no definitions in the header for these, right?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Ard Biesheuvel
maintainerQuoted 33 lines · Andy Shevchenko
Quoted 1 line · Ard Biesheuvel
On Wed, 30 Aug 2023 at 00:54, Justin Stitt <[email protected]> wrote:
...
Quoted 27 lines
Quoted 9 lines
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 variables are not externally declared anywhere (AFAIK)
They are:
drivers/firmware/efi/efi.c:extern
__weakstructkobj_attributeefi_attr_fw_vendor;
drivers/firmware/efi/efi.c:extern__weakstructkobj_attributeefi_attr_runtime; drivers/firmware/efi/efi.c:extern__weakstructkobj_attributeefi_attr_config_table;Quoted 1 line
so let's add the static keyword and ensure we follow the ODR.
This won't work.
Those variables are referenced via weak references in generic code. The idea is that the weak references resolve to NULL pointers on architectures other than x86, terminating the array early and hiding the non-existent variables.
Quoted 6 lines
Quoted 3 lines
Making them static in
arch/x86/platform/efi/efi.cmeans that these references will remain unsatisfied, and so the variables will no longer be exposed on x86 either.So it means that we have no definitions in the header for these, right?
Indeed.
If there are better ways of fixing this that don't involve weak references, I am also fine with that, but just moving the existing extern declarations into linux/efi.h is probably the easiest approach here.