Commit 1b48f743 authored by Luca Burelli's avatar Luca Burelli Committed by Benjamin Cabé
Browse files

llext: avoid redundant 'ldr_parm' checks



Since commit 0aa6b1c9, the 'ldr_parm' pointer is guaranteed to be
valid inside all the functions of the llext_load() call tree.

This commit fixes the only exception of llext_copy_strings(), which was
not passed the 'ldr_parm' pointer, and remove the redundant checks.

No functional change is intended by this commit.

Signed-off-by: default avatarLuca Burelli <l.burelli@arduino.cc>
parent c0c8f778
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ static void xtensa_elf_relocate(struct llext_loader *ldr, struct llext *ext,

	switch (type) {
	case R_XTENSA_RELATIVE:
		if (ldr_parm && ldr_parm->pre_located) {
		if (ldr_parm->pre_located) {
			/* Relative relocations are already correct in the pre-located case */
			break;
		}
+3 −3
Original line number Diff line number Diff line
@@ -560,7 +560,7 @@ static int llext_export_symbols(struct llext_loader *ldr, struct llext *ext,
		 */
		const char *name = NULL;

		if (ldr_parm && ldr_parm->pre_located) {
		if (ldr_parm->pre_located) {
			ssize_t name_offset = llext_file_offset(ldr, (uintptr_t)sym->name);

			if (name_offset > 0) {
@@ -706,7 +706,7 @@ int do_llext_load(struct llext_loader *ldr, struct llext *ext,
	}

	LOG_DBG("Allocate and copy strings...");
	ret = llext_copy_strings(ldr, ext);
	ret = llext_copy_strings(ldr, ext, ldr_parm);
	if (ret != 0) {
		LOG_ERR("Failed to copy ELF string sections, ret %d", ret);
		goto out;
@@ -772,7 +772,7 @@ out:
	 * Note that this exploits the fact that freeing a NULL pointer has no effect.
	 */

	if (ret != 0 || !ldr_parm || !ldr_parm->keep_section_info) {
	if (ret != 0 || !ldr_parm->keep_section_info) {
		llext_free_inspection_data(ldr, ext);
	}

+13 −7
Original line number Diff line number Diff line
@@ -87,10 +87,11 @@ static int llext_copy_region(struct llext_loader *ldr, struct llext *ext,
				ext->mem_on_heap[mem_idx] = false;
				return 0;
			}
		} else if (ldr_parm && ldr_parm->pre_located) {
		} else if (ldr_parm->pre_located) {
			/*
			 * ldr_parm cannot be NULL here with the current flow, but
			 * we add a check to make it future-proof
			 * In pre-located files all regions, including BSS,
			 * are placed by the user with a linker script. No
			 * additional memory allocation is needed here.
			 */
			ext->mem[mem_idx] = NULL;
			ext->mem_on_heap[mem_idx] = false;
@@ -98,7 +99,11 @@ static int llext_copy_region(struct llext_loader *ldr, struct llext *ext,
		}
	}

	if (ldr_parm && ldr_parm->pre_located) {
	if (ldr_parm->pre_located) {
		/*
		 * The ELF file is supposed to be pre-located, but some
		 * regions are not accessible or not in the correct place.
		 */
		return -EFAULT;
	}

@@ -153,12 +158,13 @@ err:
	return ret;
}

int llext_copy_strings(struct llext_loader *ldr, struct llext *ext)
int llext_copy_strings(struct llext_loader *ldr, struct llext *ext,
		       const struct llext_load_param *ldr_parm)
{
	int ret = llext_copy_region(ldr, ext, LLEXT_MEM_SHSTRTAB, NULL);
	int ret = llext_copy_region(ldr, ext, LLEXT_MEM_SHSTRTAB, ldr_parm);

	if (!ret) {
		ret = llext_copy_region(ldr, ext, LLEXT_MEM_STRTAB, NULL);
		ret = llext_copy_region(ldr, ext, LLEXT_MEM_STRTAB, ldr_parm);
	}

	return ret;
+2 −1
Original line number Diff line number Diff line
@@ -15,7 +15,8 @@
 * Memory management (llext_mem.c)
 */

int llext_copy_strings(struct llext_loader *ldr, struct llext *ext);
int llext_copy_strings(struct llext_loader *ldr, struct llext *ext,
		       const struct llext_load_param *ldr_parm);
int llext_copy_regions(struct llext_loader *ldr, struct llext *ext,
		       const struct llext_load_param *ldr_parm);
void llext_free_regions(struct llext *ext);