All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/iomem_copy: fix __iomem casts
@ 2026-06-22 12:48 Ben Dooks
  2026-06-23 23:47 ` Al Viro
  0 siblings, 1 reply; 4+ messages in thread
From: Ben Dooks @ 2026-06-22 12:48 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel; +Cc: Ben Dooks

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@codethink.co.uk>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-24  8:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 12:48 [PATCH] lib/iomem_copy: fix __iomem casts Ben Dooks
2026-06-23 23:47 ` Al Viro
2026-06-24  0:04   ` Al Viro
2026-06-24  8:21     ` David Laight

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.