Re: [PATCH v3] fs: Replace user_access_{begin/end} by scoped user access
From: David Laight
Date: Wed Mar 18 2026 - 18:37:17 EST
On Wed, 18 Mar 2026 08:53:52 -0700
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Wed, 18 Mar 2026 at 08:49, Linus Torvalds
> <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> >
> > #define dirent_size(dirent, len) offsetof(typeof(dirent), d_name[len])
>
> That 'typeof(dirent)' needs to be 'typeof(*(dirent))' to be convenient.
>
> It was correct in the patch I attached, but I'll just point it out anyway.
>
> And we actually have a helper macro for that: struct_offset(). Which
> wasn't what I used in that attached patch, but *should* have been.
>
> IOW, the macro should look something like
>
> #define dirent_size(dirent, len) struct_offset(dirent, d_name[len])
>
> instead. That looks fairly clean, no?
And unnecessary - the struct_offset() isn't that much longer.
Actually, from a readability point of view even struct_offset() almost
makes things worse.
If you are being paranoid it is another definition to find and check.
There isn't that much difference in the lengths:
dirent_size(dirent, len)
struct_offset(dirent, d_name[len])
offsetof(typeof(*dirent), d_name[len])
and the last one really does tell you what it being calculated.
I do remember one compiler (and I thought it was gcc, but it might only
have been msvc) that required that offsetof() always generate a constant.
ISTR the C language requires that - which makes all the above invalid.
>
> Linus