[PATCH 01/12] cred: add prepare credential guard

Christian Brauner <[email protected]>
Newsgroups gmane.linux.kernel.aio.general,gmane.linux.file-systems,gmane.linux.kernel,gmane.linux.file-systems.union,gmane.linux.nfs,gmane.linux.kernel.cifs,gmane.network.samba.internals,gmane.linux.kernel.cgroups,gmane.linux.network,gmane.linux.kernel.cryptoapi
Message-ID <20251103-work-creds-guards-prepare_creds-v1-1-b447b82f2c9b@kernel.org>
A lot of code uses the following pattern:

* prepare new credentials
* modify them for their use-case
* drop them

Support that easier with the new guard infrastructure.

Signed-off-by: Christian Brauner <[email protected]>
---
 include/linux/cred.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/linux/cred.h b/include/linux/cred.h
index 1778c0535b90..a1e33227e0c2 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -285,6 +285,11 @@ static inline void put_cred(const struct cred *cred)
 	put_cred_many(cred, 1);
 }
 
+DEFINE_CLASS(prepare_creds,
+	      struct cred *,
+	      if (_T) put_cred(_T),
+	      prepare_creds(), void)
+
 DEFINE_FREE(put_cred, struct cred *, if (!IS_ERR_OR_NULL(_T)) put_cred(_T))
 
 /**

-- 
2.47.3


--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to [email protected].  For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"[email protected]">[email protected]</a>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.