Re: [PATCH v2] arm64/mm: fix variable 'tag' set but not used

From: Qian Cai
Date: Thu Aug 01 2019 - 12:20:40 EST


On Thu, 2019-08-01 at 09:00 -0700, Matthew Wilcox wrote:
> On Thu, Aug 01, 2019 at 10:47:05AM -0400, Qian Cai wrote:
>
> Given this:
>
> > -#define __tag_set(addr, tag) (addr)
> > +static inline const void *__tag_set(const void *addr, u8 tag)
> > +{
> > + return addr;
> > +}
> > +
> > Â#define __tag_reset(addr) (addr)
> > Â#define __tag_get(addr) 0
> > Â#endif
> > @@ -301,8 +305,8 @@ static inline void *phys_to_virt(phys_addr_t x)
> > Â#define page_to_virt(page) ({
> > \
> > Â unsigned long __addr =
> > \
> > Â ((__page_to_voff(page)) | PAGE_OFFSET);
> > \
> > - unsigned long __addr_tag = \
> > - Â__tag_set(__addr, page_kasan_tag(page)); \
> > + const void *__addr_tag = \
> > + __tag_set((void *)__addr, page_kasan_tag(page)); \
> > Â ((void *)__addr_tag);
> > \
> > Â})
>
> Can't you simplify that macro to:
>
> Â#define page_to_virt(page) ({ \
> Â unsigned long __addr =
> \
> Â ((__page_to_voff(page)) | PAGE_OFFSET);
> \
> - unsigned long __addr_tag = \
> - Â__tag_set(__addr, page_kasan_tag(page)); \
> - ((void *)__addr_tag);
> \
> + __tag_set((void *)__addr, page_kasan_tag(page)); \
> Â})

It still need a cast or lowmem_page_address() will complain of a discarded
"const". It might be a bit harder to read when adding a cast as in,

((void *)__tag_set((void *)__addr, page_kasan_tag(page)));

But, that feel like more of a followup patch for me if ever needed.