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 <l.burelli@arduino.cc>
This commit is contained in:
Luca Burelli 2023-12-01 18:25:18 +01:00 committed by Anas Nashif
commit cbed9fd785
2 changed files with 3 additions and 1 deletions

View file

@ -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) {