Re: [PATCH] mm: Make {,set}page_address() static inline ifWANT_PAGE_VIRTUAL

From: David Rientjes
Date: Wed Jan 15 2014 - 17:58:10 EST


On Wed, 15 Jan 2014, Geert Uytterhoeven wrote:

> {,set}page_address() are macros if WANT_PAGE_VIRTUAL.
> If !WANT_PAGE_VIRTUAL, they're plain C functions.
>
> If someone calls them with a void *, this pointer is auto-converted to
> struct page * if !WANT_PAGE_VIRTUAL, but causes a build failure on
> architectures using WANT_PAGE_VIRTUAL (arc, m68k and sparc):

s/sparc/sparc64/

>
> drivers/md/bcache/bset.c: In function â__btree_sortâ:
> drivers/md/bcache/bset.c:1190: warning: dereferencing âvoid *â pointer
> drivers/md/bcache/bset.c:1190: error: request for member âvirtualâ in something not a structure or union
>
> Convert them to static inline functions to fix this. There are already
> plenty of users of struct page members inside <linux/mm.h>, so there's no
> reason to keep them as macros.
>
> Signed-off-by: Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>

Tested-by: David Rientjes <rientjes@xxxxxxxxxx>

I'm cringing at the page_address(mempool_alloc(..., GFP_NOIO)) in
drivers/md/bcache/bset.c, though. It's relying on that fact that
mempool_alloc() can never return NULL if __GFP_WAIT but I think this could
have all been avoided with

struct page *page = mempool_alloc(state->pool, GFP_NOIO);
out = page_address(page);

instead of burying the mempool_alloc() in page_address() for what I think
is cleaner code. Owell, it fixes the issue.