Received: by 10.223.176.5 with SMTP id f5csp877515wra; Tue, 30 Jan 2018 21:19:07 -0800 (PST) X-Google-Smtp-Source: AH8x224NEb4L51kW1fR1QxuXlnsgqdD1p/OmAWuVaiEmq44X49lDMuhPY8ScY94ufxHEiEukLMd1 X-Received: by 10.99.142.76 with SMTP id k73mr25518295pge.89.1517375947562; Tue, 30 Jan 2018 21:19:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517375947; cv=none; d=google.com; s=arc-20160816; b=rnLPlrSvbR5XT/bo7TFkSgLHk/jEZ/1Gf2IVBqZH4PZVxPAboMYkqvnxs6HNjkgAt4 cx8ofAf+tg+nHzcgzqwCcL5Z6a2+AoYLZgkW6x4HjC1pRG6S19xe5q9RUvwO3gcWXxOa 4GeMIj27UpfTxfjUcJkyF10vEqoFQnuZtTq5G3uIVtLl/dgaiKPnhJoaBCtAyp6n73PY nXCS1bX5o9qUedkEGjJgXwwnu6YaxWn5ti1TrWmzK4nzEthfLNp5jxsmt9ADq26Ny8o2 jr+Xbg6wm8apFvcMEsgcQkEV1JB+WJaA0QQD8XHf+MusYJ9e9zvL1zce9GhiWY3M2sCI UuKw== 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:arc-authentication-results; bh=4t2rHWzLBmHbq/JwMgXtQfEXWjMmqNeMfLpGMt+lVfs=; b=J6nEpD+AceRn01wS35c4lFaekUosq8nDsP7mBoXsAp20xKS1zyaQy9XpC4i04l2kEr KaUqeVaGBqv2JuEymYtYpxPba7yWuCyr57Ph5hbqTBrjMr6gmchjpuwl6UDPIEdelhmK qa1sRhY6WcM+BJJmJmisUX2341Po7Uhz+TBExeggpkyVz65QbCnnROZ8F6u8+k6clbBW 7VUldGv5gxYCUZ3RyTXAQeXvOlruQ3cm7kWoZ5TQQ9IG2Wj+xrrtcYip7gNtWLpXlm3Y TLIzeSQmmrrhA2Q5F6TaiXC7wnDFD6xhCBf9kMenILCok/2/vwCWHNo00mjIWIY/13yA cLFQ== 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 h89-v6si13165126pld.590.2018.01.30.21.18.53; Tue, 30 Jan 2018 21:19:07 -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 S1752749AbeAaFRB (ORCPT + 99 others); Wed, 31 Jan 2018 00:17:01 -0500 Received: from mx2.suse.de ([195.135.220.15]:35122 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752643AbeAaFQ7 (ORCPT ); Wed, 31 Jan 2018 00:16:59 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9D2D5AB40; Wed, 31 Jan 2018 05:16:57 +0000 (UTC) From: NeilBrown To: David Howells , Andrew Morton , Ingo Molnar , Anna Schumaker Date: Wed, 31 Jan 2018 16:15:39 +1100 Subject: [PATCH 4/4] cred: allow get_cred() and put_cred() to be given NULL. Cc: NFS , lkml Message-ID: <151737573957.14845.1487973111492506012.stgit@noble> In-Reply-To: <151737571564.14845.2874586176125198504.stgit@noble> References: <151737571564.14845.2874586176125198504.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 of helps like this so 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 69ed76f7d49f..c9ba3c8747e9 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -232,7 +232,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 @@ -243,6 +243,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); } @@ -263,7 +265,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 @@ -273,9 +275,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); + } } /**