Subject: Re: [PATCH] powerpc: Fix signature of pfn_to_kaddr()

From: Michael Ellerman <[email-masked]>
Date: Tue, 07 Nov 2023 16:57:40 +1100

Linus Walleij <[email-masked]> writes:
> There is a const in the returned value from pfn_to_kaddr()
> but there are consumers that want to modify the result
> and the generic function pfn_to_virt() in <asm-generic/page.h>
> does allow this, so let's relax this requirement and do not
> make the returned value const.
>
> Reported-by: kernel test robot <[email-masked]>
> Closes: https://lore.kernel.org/oe-kbuild-all/[email-masked]/
 
I'm struggling to connect the removal of const with those bug reports.
It looks like all those warnings are about 0xc000000000000000 being
outside the range of unsigned long when building 32-bit.

Is it the right bug report link?

The current signature of:

  static inline const void *pfn_to_kaddr(unsigned long pfn) ...

seems OK to me.

It allows code like:

  const void *p = pfn_to_kaddr(pfn);
  p++;

But errors for:

  const void *p = pfn_to_kaddr(pfn);
  unsigned long *q = p;
  *q = 0;

  error: initialization discards ‘const’ qualifier from pointer target type

Having said that it looks like almost every caller of pfn_to_kaddr()
casts the result to unsigned long, so possibly that would be the better
return type in terms of the actual usage. Although that would conflict
with __va() which returns void * :/

cheers