Messages in this thread | | | From | Mathieu Malaterre <> | Date | Mon, 26 Feb 2018 08:49:20 +0100 | Subject | Re: [PATCH 05/21] powerpc: Avoid comparison of unsigned long >= 0 in pfn_valid |
| |
On Mon, Feb 26, 2018 at 7:32 AM, Christophe LEROY <christophe.leroy@c-s.fr> wrote: > > > Le 25/02/2018 à 18:22, Mathieu Malaterre a écrit : >> >> Rewrite comparison since all values compared are of type `unsigned long`. >> >> Fix a warning (treated as error in W=1): >> >> 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 ‘dma_map_resource’: >> ./arch/powerpc/include/asm/page.h:129:32: error: comparison of unsigned >> expression >= 0 is always true [-Werror=type-limits] >> #define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && (pfn) < max_mapnr) >> ^ >> Suggested-by: Segher Boessenkool <segher@kernel.crashing.org> >> Signed-off-by: Mathieu Malaterre <malat@debian.org> >> --- >> 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/page.h >> 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; >> #ifdef CONFIG_FLATMEM >> #define ARCH_PFN_OFFSET ((unsigned long)(MEMORY_START >> >> PAGE_SHIFT)) >> -#define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && (pfn) < >> max_mapnr) >> +#define pfn_valid(pfn) \ >> + (((pfn) - ARCH_PFN_OFFSET) < (max_mapnr - >> ARCH_PFN_OFFSET)) > > > What will happen when ARCH_PFN_OFFSET is not nul and pfn is lower than > ARCH_PFN_OFFSET ?
I assumed that normal unsigned integers modulo would make the test fail. But for some particular value of max_mapnr the two are indeed not equivalent.
> Christophe > > >> #endif >> #define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) >> >
| |