From: Al Viro <viro@zeniv.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: [RFC] struct fd situation
Date: Fri, 31 May 2024 23:01:13 +0100 [thread overview]
Message-ID: <20240531220113.GC1629371@ZenIV> (raw)
In-Reply-To: <CAHk-=wjm3XN1rOWpOKp0=Jgce-bCUmeWvaHLmUiqsDgunUDzxw@mail.gmail.com>
On Fri, May 31, 2024 at 11:44:22AM -0700, Linus Torvalds wrote:
> The above obviously assumes that an 'fd_err' never contains NULL.
> Either it's the pointer to the fd (with whatever FDPUT_xyz bits) or
> it's an error value. I don't know if that was your plan.
Definitely. Mixing NULL and ERR_PTR() for error reporting is a bloody
bad idea; we *do* have functions that may legitimately return both,
but there NULL does not serve as an error indicator - ->lookup()
is one such case (ERR_PTR() on error, NULL - success, use dentry
passed to ->lookup(), non-NULL - a different dentry had to be
spliced in, use it instead). IS_ERR_OR_NULL() is almost always
a sign of bad calling conventions, or the author being too lazy to
check what the calling conventions are... ;-/
> You can use similar tricks to then get the error value, ie
>
> #define fd_error(f) _Generic(f, \
> struct fd: -EBADF, \
> struct fd_err: PTR_ERR((f).word))
>
> and now you can write code like
>
> if (fd_empty(x))
> return fd_error(x);
>
> and it will automagically just DTRT, regardless of whether 'x' is a
> 'struct fd' or a 'struct fd_err'.
... except that there's a sizable fraction of those checks that return
something completely different instead of -EBADF ;-/ Userland ABI,
can't do anything about it...
> The same model goes for 'fdput()' - don't make people have to use two
> names and pointlessly state the type.
Maybe, but that depends upon the amount of explicit calls of either
left when we are done. Conversions to CLASS(fd) eliminate a lot
of those...
> The bad old days where people were convinced that "Hungarian notation"
> was a good thing were bad. Let's leave them behind completely.
>
> Worth it? Who knows.. But I like your type-based approach, and I think
> that _Generic() thing would fit very very with it.
I'm fine with that for fd_empty(); for the rest... let's see how the
things look like at the end of that series.
prev parent reply other threads:[~2024-05-31 22:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-31 3:18 [RFC] struct fd situation Al Viro
2024-05-31 16:30 ` Al Viro
2024-05-31 16:40 ` Al Viro
2024-05-31 18:44 ` Linus Torvalds
2024-05-31 22:01 ` Al Viro [this message]
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=20240531220113.GC1629371@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=linux-fsdevel@vger.kernel.org \
--cc=torvalds@linux-foundation.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