Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp871410ybc; Sat, 16 Nov 2019 10:12:08 -0800 (PST) X-Google-Smtp-Source: APXvYqyMbb/gxzGcyKAUivxR3Xi40u2S5uUO8hCNrd+5yCHcWQdXp+tt+zvmZl06FFns/4fQNJ7F X-Received: by 2002:a17:906:b6c3:: with SMTP id ec3mr12128289ejb.27.1573927928478; Sat, 16 Nov 2019 10:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573927928; cv=none; d=google.com; s=arc-20160816; b=GOgTxZvO9VGkC97jFRP1tMKv/VHUsoB9aM6W1G0ZU63YLJ7lBgNT8vbERBqTfCpYIT TGPDU49sqyk+xpdZ++YhDwokLQeWy3XzBTMj4UeNrRV/9XwpUUuD8aoID+Npl2sqIjMd BxphiUdITf6lo6stAD5p+MctW7j5Lc0UtekRgbeY3IdbbrVV18yfIvh3DcKFKFNiQg4u PI92UHfkrvJDDNKUCStNdA2ndxopuaylnKvKBAce2uhAu4CwAsLv0b9a74g+vd59aeSd WJ2fSRd/iH/tHSVLMJVN7zkKRjTQzRpGm8/2TOWVqnY/XkRvgvb1/oGtuCqE1EwoXg1Z q3eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=cAqnlntQgvrz9vRto9Kadu2W6eLU3r/faPCxJk34apA=; b=DwBv2sYwVdVyoJXDEJ/831u7dPsyqlh7/i14QqrnqAh1KgVO0P8Fu7G9J2BHHxpbT1 /7mMApqrdOPNLyTEFbhrVnU/uHYKlIXuy7Wp2ZReT0tqiP+L8UW6iz6anf4PB569zanj cp/qPnSGsFoOPO8lwJrxhg2l79RmpmKkjPdGimtLwnI1H3uA46wXB73fp/kAvs2yBEdS 8BzukUWhUbTwRfCf4d3nrcJcTzpAsiUOr1Kgg5+XcIJ3kNxzHsQjJ7Bx01sSYctlP85D eur8P6z1xzrswrvJYs20v9itT7YNKeSnDlmHpTvVX1ofs9NEDY8aQXmRAWjr+m2VLnPF AXpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t18si8581711eji.130.2019.11.16.10.11.32; Sat, 16 Nov 2019 10:12:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727697AbfKPSKL (ORCPT + 99 others); Sat, 16 Nov 2019 13:10:11 -0500 Received: from mx2.suse.de ([195.135.220.15]:49284 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727437AbfKPSKK (ORCPT ); Sat, 16 Nov 2019 13:10:10 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id ECC11B13A; Sat, 16 Nov 2019 18:10:02 +0000 (UTC) Date: Sun, 17 Nov 2019 05:09:34 +1100 From: Aleksa Sarai To: Al Viro Cc: Aleksa Sarai , Jeff Layton , "J. Bruce Fields" , Arnd Bergmann , David Howells , Shuah Khan , Shuah Khan , Ingo Molnar , Peter Zijlstra , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , Eric Biederman , Andy Lutomirski , Andrew Morton , Kees Cook , Jann Horn , Tycho Andersen , David Drysdale , Chanho Min , Oleg Nesterov , Rasmus Villemoes , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Linus Torvalds , dev@opencontainers.org, containers@lists.linux-foundation.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-alpha@vger.kernel.org, linux-api@vger.kernel.org, libc-alpha@sourceware.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org, sparclinux@vger.kernel.org Subject: Re: [PATCH v16 02/12] namei: allow nd_jump_link() to produce errors Message-ID: <20191116180934.fajrkc4jqcewiuqd@yavin.dot.cyphar.com> References: <20191116002802.6663-1-cyphar@cyphar.com> <20191116002802.6663-3-cyphar@cyphar.com> <20191116003702.GX26530@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ushqsy2n2ywnjdre" Content-Disposition: inline In-Reply-To: <20191116003702.GX26530@ZenIV.linux.org.uk> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ushqsy2n2ywnjdre Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-11-16, Al Viro wrote: > On Sat, Nov 16, 2019 at 11:27:52AM +1100, Aleksa Sarai wrote: > > + error =3D nd_jump_link(&path); > > + if (error) > > + path_put(&path); >=20 > > + error =3D nd_jump_link(&ns_path); > > + if (error) > > + path_put(&ns_path); >=20 > > + error =3D nd_jump_link(&path); > > + if (error) > > + path_put(&path); >=20 > 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(). >=20 > 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. >=20 > 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 =3D=3D 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 =3D ERR_PTR(nd_jump_link(&ns_path)); Or probably (if you don't want to rely on ERR_PTR(0) =3D=3D NULL): int err =3D nd_jump_link(&ns_path); if (err) error =3D ERR_PTR(err); --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --ushqsy2n2ywnjdre Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQSxZm6dtfE8gxLLfYqdlLljIbnQEgUCXdA7WwAKCRCdlLljIbnQ EkhIAQCTW+ppymqPGqw4uOB2Z70GQdn52zl46zQ6xxp5L3kEHQD9FZ2+HHtYsZC+ LGfFupqoyojLXID+lx72AXf4CJ7KLw4= =aGSY -----END PGP SIGNATURE----- --ushqsy2n2ywnjdre--