[PATCH 1/7] x86: asm/io.h: Expect immutable pointer in virt_to_phys/isa_virt_to_bus prototypes

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

These two helper functions - virt_to_phys and isa_virt_to_bus - don'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: Thomas Gleixner <tglx@linutronix.de>
CC: Ingo Molnar <mingo@redhat.com>
CC: Borislav Petkov <bp@alien8.de>
CC: Dave Hansen <dave.hansen@linux.intel.com>
CC: x86@kernel.org
CC: "H. Peter Anvin" <hpa@zytor.com>
CC: Geert Uytterhoeven <geert@linux-m68k.org>
CC: Arnd Bergmann <arnd@arndb.de>
CC: Chris Down <chris@chrisdown.name>
CC: Helge Deller <deller@gmx.de>
CC: Omar Sandoval <osandov@fb.com>
CC: linux-kernel@vger.kernel.org
---
 arch/x86/include/asm/io.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index e9025640f634..0e6f5b48f517 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -128,7 +128,7 @@ extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
  *	this function
  */
 
-static inline phys_addr_t virt_to_phys(volatile void *address)
+static inline phys_addr_t virt_to_phys(const volatile void *address)
 {
 	return __pa(address);
 }
@@ -163,7 +163,7 @@ static inline void *phys_to_virt(phys_addr_t address)
  * However, we truncate the address to unsigned int to avoid undesirable
  * promotions in legacy drivers.
  */
-static inline unsigned int isa_virt_to_bus(volatile void *address)
+static inline unsigned int isa_virt_to_bus(const volatile void *address)
 {
 	return (unsigned int)virt_to_phys(address);
 }


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

> From: Stanislav Kinsburskii <stanislav.kinsburskii@gmail.com>
>
> These two helper functions - virt_to_phys and isa_virt_to_bus - don'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: Thomas Gleixner <tglx@linutronix.de>
> CC: Ingo Molnar <mingo@redhat.com>
> CC: Borislav Petkov <bp@alien8.de>
> CC: Dave Hansen <dave.hansen@linux.intel.com>
> CC: x86@kernel.org
> CC: "H. Peter Anvin" <hpa@zytor.com>
> CC: Geert Uytterhoeven <geert@linux-m68k.org>
> CC: Arnd Bergmann <arnd@arndb.de>
> CC: Chris Down <chris@chrisdown.name>
> CC: Helge Deller <deller@gmx.de>
> CC: Omar Sandoval <osandov@fb.com>
> CC: linux-kernel@vger.kernel.org

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

This is the right thing to do.

Yours,
Linus Walleij