lkml.org 
[lkml]   [2018]   [Feb]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 05/21] powerpc: Avoid comparison of unsigned long >= 0 in pfn_valid
On Mon, Feb 26, 2018 at 07:32:03AM +0100, Christophe LEROY wrote:
> Le 25/02/2018 à 18:22, Mathieu Malaterre a écrit :
> >-#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 ?

It will work fine.

Say you are asking for a <= x < b so (in actual integers, no overflow)
that is 0 <= x-a < b-a and you also assume x-a overflows, so that we
are actually comparing x-a+M < b-a with M = 2**32 or such (the maximum
value in the unsigned integer type plus one). This comparison is
obviously always false.

(It also works if b < a btw).


Segher

\
 
 \ /
  Last update: 2018-02-26 09:47    [W:0.233 / U:0.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site