[PATCH 7/7] asm-generic/io.h: Expect immutable pointer in virt_to_phys

Stanislav Kinsburskii posted 7 patches 2 years, 8 months ago
[PATCH 7/7] asm-generic/io.h: Expect immutable pointer in virt_to_phys
Posted by Stanislav Kinsburskii 2 years, 8 months ago
From: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>

These helper function - virt_to_phys - doesn't need the address pointer to be
mutable.

In the same time expecting it to be mutable leads to the following build
warning for constant pointers:

  warning: passing argument 1 of ‘virt_to_phys’ discards ‘const’ qualifier from pointer target type

Signed-off-by: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
CC: Arnd Bergmann <arnd@arndb.de>
CC: linux-arch@vger.kernel.org
CC: linux-kernel@vger.kernel.org
---
 include/asm-generic/io.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index 587e7e9b9a37..ee9d9584e05b 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -1000,7 +1000,7 @@ static inline void iowrite64_rep(volatile void __iomem *addr,
  */
 #ifndef virt_to_phys
 #define virt_to_phys virt_to_phys
-static inline unsigned long virt_to_phys(volatile void *address)
+static inline unsigned long virt_to_phys(const volatile void *address)
 {
 	return __pa((unsigned long)address);
 }


Re: [PATCH 7/7] asm-generic/io.h: Expect immutable pointer in virt_to_phys
Posted by Linus Walleij 2 years, 3 months ago
On Thu, Apr 27, 2023 at 7:43 PM Stanislav Kinsburskii
<skinsburskii@linux.microsoft.com> wrote:

> From: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
>
> These helper function - virt_to_phys - doesn't need the address pointer to be
> mutable.
>
> In the same time expecting it to be mutable leads to the following build
> warning for constant pointers:
>
>   warning: passing argument 1 of ‘virt_to_phys’ discards ‘const’ qualifier from pointer target type
>
> Signed-off-by: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
> CC: Arnd Bergmann <arnd@arndb.de>
> CC: linux-arch@vger.kernel.org
> CC: linux-kernel@vger.kernel.org

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

I changed several other virt_to_phys() implementations to add const to
the argument and no problems so this should work fine.

Yours,
Linus Walleij