From: Lucas De Marchi Date: Mon, 5 Dec 2011 21:40:45 +0000 (-0200) Subject: kmod_module: return a new list and increase ref of dependencies X-Git-Tag: v1~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1cd799fb0a8e4d2859189b85480cdb5668db72a;p=thirdparty%2Fkmod.git kmod_module: return a new list and increase ref of dependencies kmod_module_get_dependency is renamed to kmod_module_get_dependencies since it's returning a list. To match other APIs, now it returns a new list that user must free with kmod_module_unref_list(). --- diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 48548868..a5c7ca34 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -274,13 +274,33 @@ KMOD_EXPORT int kmod_module_unref_list(struct kmod_list *list) return 0; } -/* - * We don't increase the refcount. Maybe we should. - */ -KMOD_EXPORT struct kmod_list *kmod_module_get_dependency(const struct kmod_module *mod) +KMOD_EXPORT struct kmod_list *kmod_module_get_dependencies(const struct kmod_module *mod) { - // FIXME calculate dependency if it's not initialized - return mod->dep; + /* TODO: populate dependencies on demand */ + struct kmod_list *l, *l_new, *list_new = NULL; + + if (mod == NULL) + return NULL; + + if (!mod->init.dep) + return NULL; + + kmod_list_foreach(l, mod->dep) { + l_new = kmod_list_append(list_new, kmod_module_ref(l->data)); + if (l_new == NULL) { + kmod_module_unref(l->data); + goto fail; + } + + list_new = l_new; + } + + return list_new; + +fail: + ERR(mod->ctx, "out of memory\n"); + kmod_module_unref_list(list_new); + return NULL; } KMOD_EXPORT struct kmod_module *kmod_module_get_module(const struct kmod_list *entry) diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h index ae5c6237..81fa5a45 100644 --- a/libkmod/libkmod.h +++ b/libkmod/libkmod.h @@ -94,7 +94,7 @@ struct kmod_module *kmod_module_ref(struct kmod_module *mod); struct kmod_module *kmod_module_unref(struct kmod_module *mod); int kmod_module_unref_list(struct kmod_list *list); struct kmod_module *kmod_module_get_module(const struct kmod_list *entry); -struct kmod_list *kmod_module_get_dependency(const struct kmod_module *mod); +struct kmod_list *kmod_module_get_dependencies(const struct kmod_module *mod); int kmod_module_remove_module(struct kmod_module *mod, unsigned int flags); int kmod_module_insert_module(struct kmod_module *mod, unsigned int flags); diff --git a/libkmod/libkmod.sym b/libkmod/libkmod.sym index 7b95749f..ec3f8544 100644 --- a/libkmod/libkmod.sym +++ b/libkmod/libkmod.sym @@ -22,7 +22,7 @@ global: kmod_module_remove_module; kmod_module_insert_module; - kmod_module_get_dependency; + kmod_module_get_dependencies; kmod_module_get_module; kmod_module_get_name;