Extract the token-based list iteration inside luo_retrieve_file() into a standalone private helper luo_find_file_by_token().
This eliminates code duplication by paving the way for additional file retrieval modalities (like retrieving into an existing file descriptor) which also need to safely lookup file tracking structures from the token list before bridging payloads. No functional change intended. Signed-off-by: David Matlack <[email protected]> --- kernel/liveupdate/luo_file.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/kernel/liveupdate/luo_file.c b/kernel/liveupdate/luo_file.c index c39f96961a85..5e160836a165 100644 --- a/kernel/liveupdate/luo_file.c +++ b/kernel/liveupdate/luo_file.c @@ -549,26 +549,32 @@ void luo_file_unfreeze(struct luo_file_set *file_set, * -ENOENT if no file with the matching token is found. * Any error code returned by the handler's .retrieve() op. */ -int luo_retrieve_file(struct luo_file_set *file_set, u64 token, - struct file **filep) + +static struct luo_file *luo_find_file_by_token(struct luo_file_set *file_set, u64 token) { - struct liveupdate_file_op_args args = {0}; struct luo_file *luo_file; - bool found = false; - int err; if (list_empty(&file_set->files_list)) - return -ENOENT; + return ERR_PTR(-ENOENT); list_for_each_entry(luo_file, &file_set->files_list, list) { - if (luo_file->token == token) { - found = true; - break; - } + if (luo_file->token == token) + return luo_file; } - if (!found) - return -ENOENT; + return ERR_PTR(-ENOENT); +} + +int luo_retrieve_file(struct luo_file_set *file_set, u64 token, + struct file **filep) +{ + struct liveupdate_file_op_args args = {0}; + struct luo_file *luo_file; + int err; + + luo_file = luo_find_file_by_token(file_set, token); + if (IS_ERR(luo_file)) + return PTR_ERR(luo_file); guard(mutex)(&luo_file->mutex); if (luo_file->retrieve_status < 0) { -- 2.55.0.966.g6673acef38-goog

