]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
cred: add prepare credential guard
authorChristian Brauner <brauner@kernel.org>
Mon, 3 Nov 2025 14:57:27 +0000 (15:57 +0100)
committerChristian Brauner <brauner@kernel.org>
Tue, 4 Nov 2025 11:36:57 +0000 (12:36 +0100)
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.

Link: https://patch.msgid.link/20251103-work-creds-guards-prepare_creds-v1-1-b447b82f2c9b@kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/cred.h

index 6ea2d81a740b3bf033feca0d2e0cc8bf8a08be8c..343a140a6ba25a4e46b4e5c697a5ce671f212585 100644 (file)
@@ -280,6 +280,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))
 
 /**