From 8bb9ae944ec7e101b6c8133fdb867c847164b5a7 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Wed, 21 Aug 2019 12:04:45 -0500 Subject: [PATCH] afs: Introduce afs_FreeFirstToken Change afs_FreeOneToken to unlink the given token from its container, instead of requiring its caller to do so. Rename the function to afs_FreeFirstToken, to help indicate the change in behavior. Also, while we are changing afs_FreeTokens to accommodate this change, simplify afs_FreeTokens a little, making it resemble afs_DiscardExpiredTokens a bit more. [kaduk@mit.edu: add note about dead store elimination] Change-Id: I0cf9d8b94236c736001a38cccfa7fdfff9f3e609 Reviewed-on: https://gerrit.openafs.org/13807 Reviewed-by: Benjamin Kaduk Tested-by: Benjamin Kaduk --- src/afs/afs_tokens.c | 47 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/src/afs/afs_tokens.c b/src/afs/afs_tokens.c index 4f7ce69..7b5f3cf 100644 --- a/src/afs/afs_tokens.c +++ b/src/afs/afs_tokens.c @@ -55,26 +55,29 @@ afs_FindToken(struct tokenJar *tokens, rx_securityIndex type) } /*! - * Free a single token + * Unlink and free a single token * - * This will free the given token. No attempt is made to unlink - * the token from its container, and it is an error to attempt to - * free a token which is still linked. - * - * This performs a secure free, setting all token information to 0 - * before returning allocated data blocks to the kernel. + * This will unlink the first token in the given tokenJar, and free that token. + * This attempts to perform a secure free, setting all token information to 0 + * before returning allocated data blocks to the kernel. (Optimizing compilers + * may eliminate such a "dead store", though.) * * Intended primarily for internal use. * - * @param[in] token - * The token to free + * @param[inout] tokenPtr + * The token to unlink and free */ - static void -afs_FreeOneToken(struct tokenJar *token) +afs_FreeFirstToken(struct tokenJar **tokenPtr) { - if (token->next != NULL) - osi_Panic("Freeing linked token"); + struct tokenJar *token = *tokenPtr; + if (token == NULL) { + return; + } + + /* Unlink the token. */ + *tokenPtr = token->next; + token->next = NULL; switch (token->type) { case RX_SECIDX_KAD: @@ -103,15 +106,8 @@ afs_FreeOneToken(struct tokenJar *token) void afs_FreeTokens(struct tokenJar **tokenPtr) { - struct tokenJar *next, *tokens; - - tokens = *tokenPtr; - *tokenPtr = NULL; - while (tokens != NULL) { - next = tokens->next; - tokens->next = NULL; /* Unlink from chain */ - afs_FreeOneToken(tokens); - tokens = next; + while (*tokenPtr != NULL) { + afs_FreeFirstToken(tokenPtr); } } @@ -220,14 +216,9 @@ afs_IsTokenUsable(struct tokenJar *token, afs_int32 now) void afs_DiscardExpiredTokens(struct tokenJar **tokenPtr, afs_int32 now) { - struct tokenJar *next; - while (*tokenPtr != NULL) { if (afs_IsTokenExpired(*tokenPtr, now)) { - next = (*tokenPtr)->next; - (*tokenPtr)->next = NULL; - afs_FreeOneToken(*tokenPtr); - *tokenPtr = next; + afs_FreeFirstToken(tokenPtr); } else { tokenPtr = &(*tokenPtr)->next; } -- 1.9.4