]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: Reduce code duplication
authorTobias Stoeckmann <tobias@stoeckmann.org>
Thu, 24 Oct 2024 18:49:05 +0000 (20:49 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 29 Oct 2024 02:55:10 +0000 (21:55 -0500)
If functions exist which cover the exact explicitly written code, use
them instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/211
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod-elf.c
libkmod/libkmod-module.c

index 07c8ca8e73df84eb980ce850f80cbda6ae89d262..956000fc119efb4ca40fd82c16b387a2deb8ba10 100644 (file)
@@ -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,
index 0415e828f41ebb11b4e5b3355a14025f7d48f907..95a2073b1b2be94e73f4f227fa3c640ff147a4ca 100644 (file)
@@ -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;
 }