Re: [PATCH v3] fs: Replace user_access_{begin/end} by scoped user access

From: Christophe Leroy (CS GROUP)

Date: Wed Mar 18 2026 - 08:29:18 EST




Le 16/03/2026 à 18:12, Linus Torvalds a écrit :
On Mon, 16 Mar 2026 at 01:53, Christophe Leroy (CS GROUP)
<chleroy@xxxxxxxxxx> wrote:

- if (!user_write_access_begin(dirent,
- (unsigned long)(dirent->d_name + namlen + 1) -
- (unsigned long)dirent))
- goto efault;

This was already pretty unreadable (my bad), but..

+ scoped_user_write_access_size(dirent, (unsigned long)(dirent->d_name + namlen + 1) -
+ (unsigned long)dirent, efault) {

.. in my opinion, this is even worse. It's a 90+ character long line
(or something), *and* it continues on the next line.

Yes, yes, the old code was disgusting too, but when changing it for
something that is supposed to be easier to read, please let's make it
*really* easier to read.

(And yes, there's another case of this same pattern a bit later).

The other pattern looks similar but is not exactly the same.


Adding a helper inline function like dirent_size() might do it. And I
think it might as well be cleaned up while at it, and make it be
something like

static inline size_t dirent_size(int namelen)
{
return offsetof(struct linux_dirent, d_name) + namelen + 1;
}


...


Hmm? Can you do at least that dirent_size() kind of cleanup?

Thanks for the suggestion.

I went for a local var alternative, see v4. A helper would be of no help as the two patterns are not exactly the same:

size_t size = offsetof(struct old_linux_dirent, d_name) + namlen + 1;

size_t size = offsetof(struct compat_old_linux_dirent, d_name) + namlen + 1;


Christophe