Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6368282imu; Sun, 2 Dec 2018 16:33:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/X/sbTBT6CL8tPCfxXMW13U+FBfQWDE0lObUWVDgs00t1q43BsmZi0KxUvayu+Uelau9fst X-Received: by 2002:a17:902:b112:: with SMTP id q18mr13950528plr.255.1543797219250; Sun, 02 Dec 2018 16:33:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543797219; cv=none; d=google.com; s=arc-20160816; b=vdn/+4pGKnOb740avLa4rVDMFunYhD3AIEqEF1ruNNufJG50RwmyYcnNzANtIR/o/E mPE9komm8Gq01XTDAEenDjs+5i/+eV3yUjcrOk6lyfT/dUahTgEydvbd3dSnxR9FmRIA cYPNiJiPibG8FlwZyh8sR5PQbzkBYqL2pYyIqkoDYpb/1mwVp5JpOEnlUc8BsXEaAlG7 Bv4lolc0pXVPT43I/48mhTUWjVcf104+7+/minCwcWZaT2arkm6dDZxEt+lZGMyM7B59 y2RwpMG6vWy/cvAGHbyXTkmpsj/x3y4ar5jxeYZB1jaCrvzuFPig0xFravE5b6nRrdk5 14Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:cc:subject:date:to :from; bh=90F+bYCb47q/F5zc5O1oQUcLxRNox6GnFYCReaWUb/4=; b=wRvWdPQhb+9peelRCHte/OgXKrK3gIo3lShLH3uhNQBQpkdp8z+yiHfuzkX0N3V57Y lnJmn2o7C3NDKIXxnW4a0UTtfxE713eQqcnPQU4ge2eWNFlSypZdCc6LsnPuJfQ4VM09 4TenJyil7GusssLb8keve9bJxMQ7doT1Df0Cx8NLBUOD2KKhc4wg1YWoQQdiW/45rAAw hVJqj0iJ3BHUdU70T8NPzV1bhEY3HbMYf0VcWMaEb8IEA4JV6+5oQKOnCtgoKCyCKdsi qmag0huTxgb+/PM9T8pt2s3CX3GYRbAYUQhUV3QDVsheQyo+X3mLPUk4KDJ/CqN94z+8 a9DQ== 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 p18si11586335plo.223.2018.12.02.16.33.23; Sun, 02 Dec 2018 16:33:39 -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 S1725949AbeLCAc1 (ORCPT + 99 others); Sun, 2 Dec 2018 19:32:27 -0500 Received: from mx2.suse.de ([195.135.220.15]:40932 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725785AbeLCAc1 (ORCPT ); Sun, 2 Dec 2018 19:32:27 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9BC41ADC0; Mon, 3 Dec 2018 00:32:21 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , Chuck Lever , Jeff Layton , Trond Myklebust , Anna Schumaker Date: Mon, 03 Dec 2018 11:30:30 +1100 Subject: [PATCH 04/23] cred: allow get_cred() and put_cred() to be given NULL. Cc: Linux NFS Mailing List , linux-kernel@vger.kernel.org Message-ID: <154379703020.28598.1657780881720707861.stgit@noble> In-Reply-To: <154379689752.28598.6750646657534626618.stgit@noble> References: <154379689752.28598.6750646657534626618.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is common practice for helpers like this to silently, accept a NULL pointer. get_rpccred() and put_rpccred() used by NFS act this way and using the same interface will ease the conversion for NFS, and simplify the resulting code. Signed-off-by: NeilBrown --- include/linux/cred.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/linux/cred.h b/include/linux/cred.h index 48979fcb95cf..4907c9df86b3 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -237,7 +237,7 @@ static inline struct cred *get_new_cred(struct cred *cred) * @cred: The credentials to reference * * Get a reference on the specified set of credentials. The caller must - * release the reference. + * release the reference. If %NULL is passed, it is returned with no action. * * This is used to deal with a committed set of credentials. Although the * pointer is const, this will temporarily discard the const and increment the @@ -248,6 +248,8 @@ static inline struct cred *get_new_cred(struct cred *cred) static inline const struct cred *get_cred(const struct cred *cred) { struct cred *nonconst_cred = (struct cred *) cred; + if (!cred) + return cred; validate_creds(cred); return get_new_cred(nonconst_cred); } @@ -268,7 +270,7 @@ static inline const struct cred *get_cred_rcu(const struct cred *cred) * @cred: The credentials to release * * Release a reference to a set of credentials, deleting them when the last ref - * is released. + * is released. If %NULL is passed, nothing is done. * * This takes a const pointer to a set of credentials because the credentials * on task_struct are attached by const pointers to prevent accidental @@ -278,9 +280,11 @@ static inline void put_cred(const struct cred *_cred) { struct cred *cred = (struct cred *) _cred; - validate_creds(cred); - if (atomic_dec_and_test(&(cred)->usage)) - __put_cred(cred); + if (cred) { + validate_creds(cred); + if (atomic_dec_and_test(&(cred)->usage)) + __put_cred(cred); + } } /**