Skip to contentSkip to conversation

riscv: mm: fix 2 instances of -Wmissing-variable-declarations

PATCH Superseded Nick Desaulniers 2 participants 3 messages Aug 8, 2023 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: mm: fix 2 instances of -Wmissing-variable-declarations

I'm looking to enable -Wmissing-variable-declarations behind W=1. 0day bot spotted the following instance in ARCH=riscv builds:

arch/riscv/mm/init.c:276:7: warning: no previous extern declaration for non-static variable 'trampoline_pg_dir' [-Wmissing-variable-declarations]
276 | pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
| ^
arch/riscv/mm/init.c:276:1: note: declare 'static' if the variable is not intended to be used outside of this translation unit

  276 | pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
      | ^
  arch/riscv/mm/init.c:279:7: warning: no previous extern declaration
  for non-static variable 'early_pg_dir'
  [-Wmissing-variable-declarations]
  279 | pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
      |       ^
  arch/riscv/mm/init.c:279:1: note: declare 'static' if the variable is
  not intended to be used outside of this translation unit
  279 | pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
      | ^

These symbols are referenced by more than one translation unit, so make sure they're both declared and include the correct header for their declarations. Finally, sort the list of includes to help keep them tidy.

---
 arch/riscv/include/asm/pgtable.h | 1 +
 arch/riscv/mm/init.c             | 9 +++++----
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/riscv/include/asm/pgtable.h +1 -0
index 75970ee2bda2..4c8c0f83a974 100644
@@ -188,6 +188,7 @@ extern struct pt_alloc_ops pt_ops __initdata;
 #define PAGE_KERNEL_IO		__pgprot(_PAGE_IOREMAP)
 
 extern pgd_t swapper_pg_dir[];
+extern pgd_t trampoline_pg_dir[];
 
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 static inline int pmd_present(pmd_t pmd)
arch/riscv/mm/init.c +5 -4
index 9ce504737d18..cc0e06b4f223 100644
@@ -26,12 +26,13 @@
 #include <linux/kfence.h>
 
 #include <asm/fixmap.h>
-#include <asm/tlbflush.h>
-#include <asm/sections.h>
-#include <asm/soc.h>
 #include <asm/io.h>
-#include <asm/ptdump.h>
 #include <asm/numa.h>
+#include <asm/pgtable.h>
+#include <asm/ptdump.h>
+#include <asm/sections.h>
+#include <asm/soc.h>
+#include <asm/tlbflush.h>
 
 #include "../kernel/head.h"
 

---
base-commit: 14f9643dc90adea074a0ffb7a17d337eafc6a5cc
change-id: 20230808-riscv_static-348036edcae7

Best regards,

Signature · 1 line
Nick Desaulniers <[email protected]>
#1 lore raw
Quoted 39 lines · Nick Desaulniers

I'm looking to enable -Wmissing-variable-declarations behind W=1. 0day bot spotted the following instance in ARCH=riscv builds:

arch/riscv/mm/init.c:276:7: warning: no previous extern declaration for non-static variable 'trampoline_pg_dir' [-Wmissing-variable-declarations]
276 | pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
| ^
arch/riscv/mm/init.c:276:1: note: declare 'static' if the variable is not intended to be used outside of this translation unit

  276 | pgd_t trampoline_pg_dir[PTRS_PER_PGD] __page_aligned_bss;
      | ^
  arch/riscv/mm/init.c:279:7: warning: no previous extern declaration
  for non-static variable 'early_pg_dir'
  [-Wmissing-variable-declarations]
  279 | pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
      |       ^
  arch/riscv/mm/init.c:279:1: note: declare 'static' if the variable is
  not intended to be used outside of this translation unit
  279 | pgd_t early_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
      | ^

These symbols are referenced by more than one translation unit, so make sure they're both declared and include the correct header for their declarations. Finally, sort the list of includes to help keep them tidy.

---
 arch/riscv/include/asm/pgtable.h | 1 +
 arch/riscv/mm/init.c             | 9 +++++----
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/riscv/include/asm/pgtable.h +0 -0
index 75970ee2bda2..4c8c0f83a974 100644

arch/riscv/include/asm/pgtable.h extern struct pt_alloc_ops pt_ops __initdata; · line 191

Quoted 4 lines
arch/riscv/include/asm/pgtable.h +1 -0
@@ -188,6 +188,7 @@ extern struct pt_alloc_ops pt_ops __initdata;
 #define PAGE_KERNEL_IO		__pgprot(_PAGE_IOREMAP)
 
 extern pgd_t swapper_pg_dir[];
+extern pgd_t trampoline_pg_dir[];

Missing early_pg_dir too? It looks like there is already a declaration in arch/riscv/mm/kasan_init.c that could be hoisted here?

Quoted 34 lines
arch/riscv/include/asm/pgtable.h +0 -0
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 static inline int pmd_present(pmd_t pmd)
arch/riscv/mm/init.c +5 -5
index 9ce504737d18..cc0e06b4f223 100644
@@ -26,12 +26,13 @@
 #include <linux/kfence.h>
 
 #include <asm/fixmap.h>
-#include <asm/tlbflush.h>
-#include <asm/sections.h>
-#include <asm/soc.h>
 #include <asm/io.h>
-#include <asm/ptdump.h>
 #include <asm/numa.h>
+#include <asm/pgtable.h>
+#include <asm/ptdump.h>
+#include <asm/sections.h>
+#include <asm/soc.h>
+#include <asm/tlbflush.h>
 
 #include "../kernel/head.h"
 
 
---

base-commit: 14f9643dc90adea074a0ffb7a17d337eafc6a5cc
change-id: 20230808-riscv_static-348036edcae7

Best regards,

Signature · 1 line
Nick Desaulniers <[email protected]>
#2 lore raw
Quoted 9 lines · Nathan Chancellor
Quoted 7 lines · Nick Desaulniers
arch/riscv/include/asm/pgtable.h +0 -0
index 75970ee2bda2..4c8c0f83a974 100644
@@ -188,6 +188,7 @@ extern struct pt_alloc_ops pt_ops __initdata;
 #define PAGE_KERNEL_IO               __pgprot(_PAGE_IOREMAP)
 
Quoted 5 lines

arch/riscv/include/asm/pgtable.h extern struct pt_alloc_ops pt_ops __initdata; · line 191

Quoted 2 lines
arch/riscv/include/asm/pgtable.h +1 -0
 extern pgd_t swapper_pg_dir[];
+extern pgd_t trampoline_pg_dir[];

Missing early_pg_dir too? It looks like there is already a declaration in arch/riscv/mm/kasan_init.c that could be hoisted here?

Yep, will respin. Good catch!

Signature · 2 lines
Thanks,
~Nick Desaulniers