From cbed9fd785efdf8c62f55c39280bc6086917b1d3 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Fri, 1 Dec 2023 18:25:18 +0100 Subject: [PATCH] llext: always initialize ext param in llext_load It is not safe to assume that on entry to llext_load, *ext contains either NULL or a previous reference to the same ext being loaded. For example, the shell sample was passing an uninitialized value. Initialize *ext from a search of the llext by name. If NULL, it is the first instance of this llext (and on load error, it stays that way). If not NULL, increment use count and return. Signed-off-by: Luca Burelli --- include/zephyr/llext/llext.h | 2 +- subsys/llext/llext.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/zephyr/llext/llext.h b/include/zephyr/llext/llext.h index af215e6acc0..b10ba2468ae 100644 --- a/include/zephyr/llext/llext.h +++ b/include/zephyr/llext/llext.h @@ -121,7 +121,7 @@ struct llext_load_param { * * @param[in] loader An extension loader that provides input data and context * @param[in] name A string identifier for the extension - * @param[out] ext A pointer to a statically allocated llext struct + * @param[out] ext This will hold the pointer to the llext struct * @param[in] ldr_parm Loader parameters * * @retval 0 Success diff --git a/subsys/llext/llext.c b/subsys/llext/llext.c index 77a741f0636..80d83dbb152 100644 --- a/subsys/llext/llext.c +++ b/subsys/llext/llext.c @@ -894,6 +894,8 @@ int llext_load(struct llext_loader *ldr, const char *name, struct llext **ext, int ret; elf_ehdr_t ehdr; + *ext = llext_by_name(name); + k_mutex_lock(&llext_lock, K_FOREVER); if (*ext) {