[PATCH] lib/iomem_copy: fix __iomem casts
From: Ben Dooks
Date: Mon Jun 22 2026 - 08:49:17 EST
The iomem_copy.c code discards __iomem address space when using
the IS_ALIGNED() macro. It would make more sense to fix this in
one place by aing a PTR_ALIGNED_LONG() macro and then doing the
necessary casts there before invoking IS_ALIGNED().
As part of this, also force the pointer to an unsigned long as
pointers are generally not signed, although there is no warning
as yet on treating pointers as signed.
lib/iomem_copy.c:27:26: warning: cast removes address space '__iomem' of expression
lib/iomem_copy.c:27:26: warning: cast removes address space '__iomem' of expression
lib/iomem_copy.c:64:26: warning: cast removes address space '__iomem' of expression
lib/iomem_copy.c:64:26: warning: cast removes address space '__iomem' of expression
lib/iomem_copy.c:106:26: warning: cast removes address space '__iomem' of expression
lib/iomem_copy.c:106:26: warning: cast removes address space '__iomem' of expression
Signed-off-by: Ben Dooks <ben.dooks@xxxxxxxxxxxxxxx>
---
lib/iomem_copy.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/iomem_copy.c b/lib/iomem_copy.c
index dec7eaea60e0..a8cd2642e3ee 100644
--- a/lib/iomem_copy.c
+++ b/lib/iomem_copy.c
@@ -9,6 +9,8 @@
#include <linux/types.h>
#include <linux/unaligned.h>
+#define PTR_ALIGNED_LONG(__ptr) IS_ALIGNED((__force unsigned long)__ptr, sizeof(long))
+
#ifndef memset_io
/**
* memset_io() - Set a range of I/O memory to a constant value
@@ -24,7 +26,7 @@ void memset_io(volatile void __iomem *addr, int val, size_t count)
qc *= ~0UL / 0xff;
- while (count && !IS_ALIGNED((long)addr, sizeof(long))) {
+ while (count && !PTR_ALIGNED_LONG(addr)) {
__raw_writeb(val, addr);
addr++;
count--;
@@ -61,7 +63,7 @@ EXPORT_SYMBOL(memset_io);
*/
void memcpy_fromio(void *dst, const volatile void __iomem *src, size_t count)
{
- while (count && !IS_ALIGNED((long)src, sizeof(long))) {
+ while (count && !PTR_ALIGNED_LONG(src)) {
*(u8 *)dst = __raw_readb(src);
src++;
dst++;
@@ -103,7 +105,7 @@ EXPORT_SYMBOL(memcpy_fromio);
*/
void memcpy_toio(volatile void __iomem *dst, const void *src, size_t count)
{
- while (count && !IS_ALIGNED((long)dst, sizeof(long))) {
+ while (count && !PTR_ALIGNED_LONG(dst)) {
__raw_writeb(*(u8 *)src, dst);
src++;
dst++;
--
2.37.2.352.g3c44437643