[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20191116180934.fajrkc4jqcewiuqd@yavin.dot.cyphar.com>
Date: Sun, 17 Nov 2019 05:09:34 +1100
From: Aleksa Sarai <asarai@...e.de>
To: Al Viro <viro@...iv.linux.org.uk>
Cc: Aleksa Sarai <cyphar@...har.com>, Jeff Layton <jlayton@...nel.org>,
"J. Bruce Fields" <bfields@...ldses.org>,
Arnd Bergmann <arnd@...db.de>,
David Howells <dhowells@...hat.com>,
Shuah Khan <shuah@...nel.org>,
Shuah Khan <skhan@...uxfoundation.org>,
Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
Andrii Nakryiko <andriin@...com>,
Eric Biederman <ebiederm@...ssion.com>,
Andy Lutomirski <luto@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Kees Cook <keescook@...omium.org>,
Jann Horn <jannh@...gle.com>, Tycho Andersen <tycho@...ho.ws>,
David Drysdale <drysdale@...gle.com>,
Chanho Min <chanho.min@....com>,
Oleg Nesterov <oleg@...hat.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...hat.com>,
Namhyung Kim <namhyung@...nel.org>,
Christian Brauner <christian@...uner.io>,
Linus Torvalds <torvalds@...ux-foundation.org>,
dev@...ncontainers.org, containers@...ts.linux-foundation.org,
bpf@...r.kernel.org, netdev@...r.kernel.org,
linux-alpha@...r.kernel.org, linux-api@...r.kernel.org,
libc-alpha@...rceware.org, linux-arch@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-fsdevel@...r.kernel.org, linux-ia64@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
linux-m68k@...ts.linux-m68k.org, linux-mips@...r.kernel.org,
linux-parisc@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
linux-s390@...r.kernel.org, linux-sh@...r.kernel.org,
linux-xtensa@...ux-xtensa.org, sparclinux@...r.kernel.org
Subject: Re: [PATCH v16 02/12] namei: allow nd_jump_link() to produce errors
On 2019-11-16, Al Viro <viro@...iv.linux.org.uk> wrote:
> On Sat, Nov 16, 2019 at 11:27:52AM +1100, Aleksa Sarai wrote:
> > + error = nd_jump_link(&path);
> > + if (error)
> > + path_put(&path);
>
> > + error = nd_jump_link(&ns_path);
> > + if (error)
> > + path_put(&ns_path);
>
> > + error = nd_jump_link(&path);
> > + if (error)
> > + path_put(&path);
>
> 3 calls. Exact same boilerplate in each to handle a failure case.
> Which spells "wrong calling conventions"; it's absolutely clear
> that we want that path_put() inside nd_jump_link().
>
> The rule should be this: reference that used to be held in
> *path is consumed in any case. On success it goes into
> nd->path, on error it's just dropped, but in any case, the
> caller has the same refcounting environment to deal with.
>
> If you need the same boilerplate cleanup on failure again and again,
> the calling conventions are wrong and need to be fixed.
Will do.
> And I'm not sure that int is the right return type here, to be honest.
> void * might be better - return ERR_PTR() or NULL, so that the value
> could be used as return value of ->get_link() that calls that thing.
I don't agree, given that the few callers of ns_get_path() are
inconsistent with regards to whether they should use IS_ERR() or check
for NULL, not to mention that "void *error" reads to me as being very
odd given how common "int error" is throughout the kernel. There's also
the "error == ERR_PTR(-EAGAIN)" checks which also read as being quite
odd too.
But the main motivating factor for changing it was that the one use
where "void *" is useful (proc_ns_get_link) becomes needlessly ugly
because of the "nd_jump_link() can return errors" change:
error = ERR_PTR(nd_jump_link(&ns_path));
Or probably (if you don't want to rely on ERR_PTR(0) == NULL):
int err = nd_jump_link(&ns_path);
if (err)
error = ERR_PTR(err);
--
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>
Download attachment "signature.asc" of type "application/pgp-signature" (229 bytes)
Powered by blists - more mailing lists