From 290e7dee9f6043d677f08dc06e612e13ee0d2d83 Mon Sep 17 00:00:00 2001 From: Heiner Kallweit Date: Tue, 31 Mar 2020 23:02:47 +0200 Subject: [PATCH 1/2] depmod: add helper mod_add_dep_unique Create new helper mod_add_dep_unique(), next patch in this series will also make use of it. Signed-off-by: Heiner Kallweit --- tools/depmod.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tools/depmod.c b/tools/depmod.c index 875e314..5419d4d 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -907,23 +907,35 @@ static void mod_free(struct mod *mod) free(mod); } -static int mod_add_dependency(struct mod *mod, struct symbol *sym) +static int mod_add_dep_unique(struct mod *mod, struct mod *dep) { int err; - DBG("%s depends on %s %s\n", mod->path, sym->name, - sym->owner != NULL ? sym->owner->path : "(unknown)"); - - if (sym->owner == NULL) + if (dep == NULL) return 0; - err = array_append_unique(&mod->deps, sym->owner); + err = array_append_unique(&mod->deps, dep); if (err == -EEXIST) return 0; if (err < 0) return err; - sym->owner->users++; + dep->users++; + + return 1; +} + +static int mod_add_dependency(struct mod *mod, struct symbol *sym) +{ + int err; + + DBG("%s depends on %s %s\n", mod->path, sym->name, + sym->owner != NULL ? sym->owner->path : "(unknown)"); + + err = mod_add_dep_unique(mod, sym->owner); + if (err <= 0) + return err; + SHOW("%s needs \"%s\": %s\n", mod->path, sym->name, sym->owner->path); return 0; } -- 2.26.0