Skip to contentSkip to conversation

MIPS: Use address-of operator on section symbols

PATCH Applied Nathan Chancellor 3 participants 3 messages Jan 5, 2021 – Jan 7, 2021

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

PATCH 1/1 MIPS: Use address-of operator on section symbols

When building xway_defconfig with clang:

arch/mips/lantiq/prom.c:82:23: error: array comparison always evaluates to true [-Werror,-Wtautological-compare]

        else if (__dtb_start != __dtb_end)
                             ^

1 error generated.

These are not true arrays, they are linker defined symbols, which are just addresses. Using the address of operator silences the warning and does not change the resulting assembly with either clang/ld.lld or gcc/ld (tested with diff + objdump -Dr). Do the same thing across the entire MIPS subsystem to ensure there are no more warnings around this type of comparison.

---
 arch/mips/bmips/setup.c          | 2 +-
 arch/mips/lantiq/prom.c          | 2 +-
 arch/mips/pic32/pic32mzda/init.c | 2 +-
 arch/mips/ralink/of.c            | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
arch/mips/bmips/setup.c +1 -1
index 19308df5f577..1b06b25aea87 100644
@@ -167,7 +167,7 @@ void __init plat_mem_setup(void)
 		dtb = phys_to_virt(fw_arg2);
 	else if (fw_passed_dtb) /* UHI interface or appended dtb */
 		dtb = (void *)fw_passed_dtb;
-	else if (__dtb_start != __dtb_end)
+	else if (&__dtb_start != &__dtb_end)
 		dtb = (void *)__dtb_start;
 	else
 		panic("no dtb found");
arch/mips/lantiq/prom.c +1 -1
index 51a218f04fe0..3f568f5aae2d 100644
@@ -79,7 +79,7 @@ void __init plat_mem_setup(void)
 
 	if (fw_passed_dtb) /* UHI interface */
 		dtb = (void *)fw_passed_dtb;
-	else if (__dtb_start != __dtb_end)
+	else if (&__dtb_start != &__dtb_end)
 		dtb = (void *)__dtb_start;
 	else
 		panic("no dtb found");
arch/mips/pic32/pic32mzda/init.c +1 -1
index 50f376f058f4..f232c77ff526 100644
@@ -28,7 +28,7 @@ static ulong get_fdtaddr(void)
 	if (fw_passed_dtb && !fw_arg2 && !fw_arg3)
 		return (ulong)fw_passed_dtb;
 
-	if (__dtb_start < __dtb_end)
+	if (&__dtb_start < &__dtb_end)
 		ftaddr = (ulong)__dtb_start;
 
 	return ftaddr;
arch/mips/ralink/of.c +1 -1
index cbae9d23ab7f..2c9af61efc20 100644
@@ -75,7 +75,7 @@ void __init plat_mem_setup(void)
 	 */
 	if (fw_passed_dtb)
 		dtb = (void *)fw_passed_dtb;
-	else if (__dtb_start != __dtb_end)
+	else if (&__dtb_start != &__dtb_end)
 		dtb = (void *)__dtb_start;
 
 	__dt_setup_arch(dtb);

base-commit: 36bbbd0e234d817938bdc52121a0f5473b3e58f5

Signature · 1 line
2.30.0
Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Nathan Chancellor

When building xway_defconfig with clang:

arch/mips/lantiq/prom.c:82:23: error: array comparison always evaluates to true [-Werror,-Wtautological-compare]

        else if (__dtb_start != __dtb_end)
                             ^

1 error generated.

These are not true arrays, they are linker defined symbols, which are just addresses. Using the address of operator silences the warning and does not change the resulting assembly with either clang/ld.lld or gcc/ld (tested with diff + objdump -Dr). Do the same thing across the entire MIPS subsystem to ensure there are no more warnings around this type of comparison.

Quoted 2 lines
Signature · 1 line
Florian
maintainer Applied
#2 lore raw
In reply to Nathan Chancellor
Quoted 15 lines · Nathan Chancellor

When building xway_defconfig with clang:

arch/mips/lantiq/prom.c:82:23: error: array comparison always evaluates to true [-Werror,-Wtautological-compare]

        else if (__dtb_start != __dtb_end)
                             ^

1 error generated.

These are not true arrays, they are linker defined symbols, which are just addresses. Using the address of operator silences the warning and does not change the resulting assembly with either clang/ld.lld or gcc/ld (tested with diff + objdump -Dr). Do the same thing across the entire MIPS subsystem to ensure there are no more warnings around this type of comparison.

Quoted 8 lines
---
 arch/mips/bmips/setup.c          | 2 +-
 arch/mips/lantiq/prom.c          | 2 +-
 arch/mips/pic32/pic32mzda/init.c | 2 +-
 arch/mips/ralink/of.c            | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

applied to mips-next.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]