Re: [PATCH] uaccess: Fix build of scoped user access with const pointer

From: Linus Torvalds

Date: Sun Mar 01 2026 - 15:01:36 EST


On Sun, 1 Mar 2026 at 11:34, Christophe Leroy (CS GROUP)
<chleroy@xxxxxxxxxx> wrote:
>
> - for (void __user *_tmpptr = __scoped_user_access_begin(mode, uptr, size, elbl); \
> + for (void __user *_tmpptr = (void __user *) \
> + __scoped_user_access_begin(mode, uptr, size, elbl); \

Why are you casting this return value? Wouldn't it be a lot better to
just make the types be the CORRECT ones?

I didn't test this, so maybe I'm missing something, but why isn't that
just doing

for (auto _tmpptr = __scoped_user_access_begin(mode, uptr,
size, elbl); \

instead? No cast, just a "use the right type automatically".

That macro actually does something similar just a few lines later, in
that the innermost loop uses

for (const typeof(uptr) uptr = _tmpptr; !done; done = true)

which picks up the type automatically from the argument (and then it
uses the argument both for the type and name, which is horrendously
confusing, but that's a separate thing).

Does that simple "auto" approach break something else?

Linus