From ed28efa53bedcae980fabb12e41de6da4747dbe9 Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Thu, 24 Oct 2024 20:49:05 +0200 Subject: [PATCH] libkmod: Reduce code duplication If functions exist which cover the exact explicitly written code, use them instead. Signed-off-by: Tobias Stoeckmann Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/211 Signed-off-by: Lucas De Marchi --- libkmod/libkmod-elf.c | 6 +----- libkmod/libkmod-module.c | 9 +-------- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c index 07c8ca8e..956000fc 100644 --- a/libkmod/libkmod-elf.c +++ b/libkmod/libkmod-elf.c @@ -251,7 +251,6 @@ fail: struct kmod_elf *kmod_elf_new(const void *memory, off_t size) { struct kmod_elf *elf; - uint64_t min_size; size_t shdrs_size, shdr_size; int err; const char *name; @@ -319,11 +318,8 @@ struct kmod_elf *kmod_elf_new(const void *memory, off_t size) goto invalid; } shdrs_size = shdr_size * elf->header.section.count; - if (uadd64_overflow(shdrs_size, elf->header.section.offset, &min_size) || - min_size > elf->size) { - ELFDBG(elf, "file is too short to hold sections\n"); + if (!elf_range_valid(elf, elf->header.section.offset, shdrs_size)) goto invalid; - } if (elf_get_section_info(elf, elf->header.strings.section, &elf->header.strings.offset, &elf->header.strings.size, diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 0415e828..95a2073b 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -573,8 +573,6 @@ KMOD_EXPORT const char *kmod_module_get_name(const struct kmod_module *mod) KMOD_EXPORT const char *kmod_module_get_path(const struct kmod_module *mod) { - char *line; - if (mod == NULL) return NULL; @@ -586,12 +584,7 @@ KMOD_EXPORT const char *kmod_module_get_path(const struct kmod_module *mod) return NULL; /* lazy init */ - line = kmod_search_moddep(mod->ctx, mod->name); - if (line == NULL) - return NULL; - - kmod_module_parse_depline((struct kmod_module *)mod, line); - free(line); + module_get_dependencies_noref(mod); return mod->path; } -- 2.47.3