From: Al Viro <viro@zeniv.linux.org.uk>
To: Ben Dooks <ben.dooks@codethink.co.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/iomem_copy: fix __iomem casts
Date: Wed, 24 Jun 2026 00:47:20 +0100 [thread overview]
Message-ID: <20260623234720.GG2636677@ZenIV> (raw)
In-Reply-To: <20260622124857.379868-1-ben.dooks@codethink.co.uk>
On Mon, Jun 22, 2026 at 01:48:57PM +0100, Ben Dooks wrote:
> 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.
> +#define PTR_ALIGNED_LONG(__ptr) IS_ALIGNED((__force unsigned long)__ptr, sizeof(long))
Casting to unsigned long is fine (indeed, casting a pointer to long had
been very odd in the first place), but... why __force? Casts to unsigned long
(de facto uintptr_t) do *not* require __force - they are explicitly allowed,
unless you pass -Wcast-from-as in sparse arguments. -Wall does not turn
those on; -Wsparse-all would, but kbuild doesn't pass that.
; cat >/tmp/a.c <<'EOF'
#define __iomem __attribute__((noderef, address_space(__iomem)))
static int f(void __iomem *p)
{
return (unsigned long)p;
}
static int g(void __iomem *p)
{
return (long)p;
}
EOF
; sparse /tmp/a.c
/tmp/a.c:10:17: warning: cast removes address space '__iomem' of expression
; sparse -Wcast-from-as /tmp/a.c
/tmp/a.c:5:17: warning: cast removes address space '__iomem' of expression
/tmp/a.c:10:17: warning: cast removes address space '__iomem' of expression
; sparse -Wall /tmp/a.c
/tmp/a.c:10:17: warning: cast removes address space '__iomem' of expression
; sparse -Wsparse-all /tmp/a.c
/tmp/a.c:5:17: warning: cast removes address space '__iomem' of expression
/tmp/a.c:10:17: warning: cast removes address space '__iomem' of expression
next prev parent reply other threads:[~2026-06-23 23:47 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 12:48 [PATCH] lib/iomem_copy: fix __iomem casts Ben Dooks
2026-06-23 23:47 ` Al Viro [this message]
2026-06-24 0:04 ` Al Viro
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=20260623234720.GG2636677@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=akpm@linux-foundation.org \
--cc=ben.dooks@codethink.co.uk \
--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