Thread (83 messages) flat view 83 messages, 6 authors, 2018-03-27

Re: [PATCH 05/21] powerpc: Avoid comparison of unsigned long >= 0 in pfn_valid

From: Michael Ellerman <mpe@ellerman.id.au>
Date: 2018-03-04 10:55:22
Also in: lkml

Mathieu Malaterre [off-list ref] writes:
Rewrite comparison since all values compared are of type `unsigned long`.

Fix a warning (treated as error in W=3D1):

  CC      arch/powerpc/kernel/irq.o
In file included from ./include/linux/bug.h:5:0,
                 from ./include/linux/cpumask.h:13,
                 from ./include/linux/smp.h:13,
                 from ./include/linux/kernel_stat.h:5,
                 from arch/powerpc/kernel/irq.c:35:
./include/linux/dma-mapping.h: In function =E2=80=98dma_map_resource=E2=
=80=99:
./arch/powerpc/include/asm/page.h:129:32: error: comparison of unsigned e=
xpression >=3D 0 is always true [-Werror=3Dtype-limits]
quoted hunk ↗ jump to hunk
 #define pfn_valid(pfn)  ((pfn) >=3D ARCH_PFN_OFFSET && (pfn) < max_mapnr)
                                ^
Suggested-by: Segher Boessenkool <redacted>
Signed-off-by: Mathieu Malaterre <redacted>
---
 arch/powerpc/include/asm/page.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/p=
age.h
quoted hunk ↗ jump to hunk
index 8da5d4c1cab2..19dea64e7ed2 100644
--- a/arch/powerpc/include/asm/page.h
+++ b/arch/powerpc/include/asm/page.h
@@ -126,7 +126,8 @@ extern long long virt_phys_offset;
=20=20
 #ifdef CONFIG_FLATMEM
 #define ARCH_PFN_OFFSET		((unsigned long)(MEMORY_START >> PAGE_SHIFT))
-#define pfn_valid(pfn)		((pfn) >=3D ARCH_PFN_OFFSET && (pfn) < max_mapnr)
+#define pfn_valid(pfn) \
+		(((pfn) - ARCH_PFN_OFFSET) < (max_mapnr - ARCH_PFN_OFFSET))
I'm not a big fan of this one, because the original code is *far* more
obvious as to what it's doing.

I'm not sure if we can make this one a static inline, or whether that
would help, but it would be worth investigating.

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help