Skip to contentSkip to conversation

RISC-V: Fix up a cherry-pick warning in setup_vm_final()

PATCH In review Palmer Dabbelt 3 participants 3 messages Apr 29, 2023 – May 6, 2023

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

PATCH 1/1 RISC-V: Fix up a cherry-pick warning in setup_vm_final()

This triggers a -Wdeclaration-after-statement as the code has changed a bit since upstream. It might be better to hoist the whole block up, but this is a smaller change so I went with it.

arch/riscv/mm/init.c:755:16: warning: mixing declarations and code is a C99 extension [-Wdeclaration-after-statement]

            unsigned long idx = pgd_index(__fix_to_virt(FIX_FDT));
                          ^
    1 warning generated.

---
I haven't even build tested this one, but it looks simple enough that I figured I'd just send it. Be warned, though: I broke glibc and missed a merged conflict yesterday...

---
 arch/riscv/mm/init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/mm/init.c +2 -1
index e800d7981e99..8d67f43f1865 100644
@@ -717,6 +717,7 @@ static void __init setup_vm_final(void)
 	uintptr_t va, map_size;
 	phys_addr_t pa, start, end;
 	u64 i;
+	unsigned long idx;
 
 	/**
 	 * MMU is enabled at this point. But page table setup is not complete yet.
@@ -735,7 +736,7 @@ static void __init setup_vm_final(void)
 	 * directly in swapper_pg_dir in addition to the pgd entry that points
 	 * to fixmap_pte.
 	 */
-	unsigned long idx = pgd_index(__fix_to_virt(FIX_FDT));
+	idx = pgd_index(__fix_to_virt(FIX_FDT));
 
 	set_pgd(&swapper_pg_dir[idx], early_pg_dir[idx]);
 #endif
Signature · 1 line
2.40.0
#1 lore raw

Hi Palmer,

Quoted 33 lines · Palmer Dabbelt

This triggers a -Wdeclaration-after-statement as the code has changed a bit since upstream. It might be better to hoist the whole block up, but this is a smaller change so I went with it.

arch/riscv/mm/init.c:755:16: warning: mixing declarations and code is a C99 extension [-Wdeclaration-after-statement]

             unsigned long idx = pgd_index(__fix_to_virt(FIX_FDT));
                           ^
     1 warning generated.

---
I haven't even build tested this one, but it looks simple enough that I figured I'd just send it. Be warned, though: I broke glibc and missed a merged conflict yesterday...

---
  arch/riscv/mm/init.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -0
index e800d7981e99..8d67f43f1865 100644
@@ -717,6 +717,7 @@ static void __init setup_vm_final(void)
  	uintptr_t va, map_size;
  	phys_addr_t pa, start, end;
  	u64 i;
+	unsigned long idx;
 
  	/**
  	 * MMU is enabled at this point. But page table setup is not complete yet.

arch/riscv/mm/init.c static void __init setup_vm_final(void) · line 742

Quoted 8 lines
arch/riscv/mm/init.c +1 -1
@@ -735,7 +736,7 @@ static void __init setup_vm_final(void)
  	 * directly in swapper_pg_dir in addition to the pgd entry that points
  	 * to fixmap_pte.
  	 */
-	unsigned long idx = pgd_index(__fix_to_virt(FIX_FDT));
+	idx = pgd_index(__fix_to_virt(FIX_FDT));
 
  	set_pgd(&swapper_pg_dir[idx], early_pg_dir[idx]);
  #endif

The above results to in rv64:

../arch/riscv/mm/init.c: In function ‘setup_vm_final’:
../arch/riscv/mm/init.c:720:16: warning: unused variable ‘idx’ [-Wunused-variable] 720 |  unsigned long idx;

The following fixes this warning:

arch/riscv/mm/init.c +0 -0
index 8d67f43f1865..e69d82d573f1 100644
@@ -717,7 +717,7 @@ static void __init setup_vm_final(void)

        uintptr_t va, map_size;
        phys_addr_t pa, start, end;
        u64 i;
-       unsigned long idx;
+       unsigned long idx __maybe_unused;

        /**
         * MMU is enabled at this point. But page table setup is not complete yet.

Let me know if you want me to send a proper patch as I'm the one to blame here.

Thanks for your patch,

Alex

maintainer
#2 lore raw
Quoted 70 lines · Alexandre Ghiti

Hi Palmer,

Quoted 32 lines · Palmer Dabbelt

This triggers a -Wdeclaration-after-statement as the code has changed a bit since upstream. It might be better to hoist the whole block up, but this is a smaller change so I went with it.

arch/riscv/mm/init.c:755:16: warning: mixing declarations and code is a C99 extension [-Wdeclaration-after-statement]

             unsigned long idx = pgd_index(__fix_to_virt(FIX_FDT));
                           ^
     1 warning generated.

---
I haven't even build tested this one, but it looks simple enough that I figured I'd just send it. Be warned, though: I broke glibc and missed a merged conflict yesterday...

---
  arch/riscv/mm/init.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/mm/init.c +1 -0
index e800d7981e99..8d67f43f1865 100644
@@ -717,6 +717,7 @@ static void __init setup_vm_final(void)
  	uintptr_t va, map_size;
  	phys_addr_t pa, start, end;
  	u64 i;
+	unsigned long idx;
  	/**
  	 * MMU is enabled at this point. But page table setup is not complete yet.

arch/riscv/mm/init.c static void __init setup_vm_final(void) · line 741

Quoted 7 lines
arch/riscv/mm/init.c +1 -1
@@ -735,7 +736,7 @@ static void __init setup_vm_final(void)
  	 * directly in swapper_pg_dir in addition to the pgd entry that points
  	 * to fixmap_pte.
  	 */
-	unsigned long idx = pgd_index(__fix_to_virt(FIX_FDT));
+	idx = pgd_index(__fix_to_virt(FIX_FDT));
  	set_pgd(&swapper_pg_dir[idx], early_pg_dir[idx]);
  #endif

The above results to in rv64:

../arch/riscv/mm/init.c: In function ‘setup_vm_final’:
../arch/riscv/mm/init.c:720:16: warning: unused variable ‘idx’ [-Wunused-variable]
  720 |  unsigned long idx;

The following fixes this warning:

arch/riscv/mm/init.c +1 -1
index 8d67f43f1865..e69d82d573f1 100644
@@ -717,7 +717,7 @@ static void __init setup_vm_final(void)
         uintptr_t va, map_size;
         phys_addr_t pa, start, end;
         u64 i;
-       unsigned long idx;
+       unsigned long idx __maybe_unused;
 
         /**
          * MMU is enabled at this point. But page table setup is not

complete yet.

Quoted 2 lines

Let me know if you want me to send a proper patch as I'm the one to blame here.

As the original fix here will not work, a "correct" one might be best to have :)

thanks,

greg k-h