Skip to content

Commit c5c92c6

Browse files
committed
smb: use credential guards in cifs_get_spnego_key()
Use credential guards for scoped credential override with automatic restoration on scope exit. Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-13-a3e156839e7f@kernel.org Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent f41799b commit c5c92c6

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

fs/smb/client/cifs_spnego.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo,
9090
size_t desc_len;
9191
struct key *spnego_key;
9292
const char *hostname = server->hostname;
93-
const struct cred *saved_cred;
9493

9594
/* length of fields (with semicolons): ver=0xyz ip4=ipaddress
9695
host=hostname sec=mechanism uid=0xFF user=username */
@@ -158,9 +157,8 @@ cifs_get_spnego_key(struct cifs_ses *sesInfo,
158157
dp += sprintf(dp, ";upcall_target=app");
159158

160159
cifs_dbg(FYI, "key description = %s\n", description);
161-
saved_cred = override_creds(spnego_cred);
162-
spnego_key = request_key(&cifs_spnego_key_type, description, "");
163-
revert_creds(saved_cred);
160+
scoped_with_creds(spnego_cred)
161+
spnego_key = request_key(&cifs_spnego_key_type, description, "");
164162

165163
#ifdef CONFIG_CIFS_DEBUG2
166164
if (cifsFYI && !IS_ERR(spnego_key)) {

0 commit comments

Comments
 (0)