From: Ben Dooks <ben.dooks@codethink.co.uk>
To: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Cc: Ben Dooks <ben.dooks@codethink.co.uk>
Subject: [PATCH] lib/iomem_copy: fix __iomem casts
Date: Mon, 22 Jun 2026 13:48:57 +0100 [thread overview]
Message-ID: <20260622124857.379868-1-ben.dooks@codethink.co.uk> (raw)
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
next reply other threads:[~2026-06-22 12:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 12:48 Ben Dooks [this message]
2026-06-23 23:47 ` Al Viro
2026-06-24 0:04 ` Al Viro
2026-06-24 8:21 ` David Laight
2026-06-24 10:17 ` Ben Dooks
2026-06-24 16:25 ` Al Viro
2026-06-29 11:14 ` Ben Dooks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260622124857.379868-1-ben.dooks@codethink.co.uk \
--to=ben.dooks@codethink.co.uk \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®