Re: [PATCH] lib/iomem_copy: fix __iomem casts

From: David Laight

Date: Wed Jun 24 2026 - 04:23:15 EST


On Wed, 24 Jun 2026 01:04:36 +0100
Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:

> On Wed, Jun 24, 2026 at 12:47:20AM +0100, Al Viro wrote:
> > 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.
>
> FWIW, we have 170+ places where IS_ALIGNED((unsigned long)pointer, _)
> or IS_ALIGNED((uintptr_t)pointer, _) is used in the tree...
>

Would is be better to add an IS_PTR_UNALIGNED(ptr, type) that returns
(unsigned long)(ptr) & (sizeof(type) - 1)
since I suspect quite a few of those places do fixups and need the offset?

David