mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-11-23 23:10:53 +07:00
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().
This commit is contained in:
parent
d2d648dfaf
commit
f1cd799fb0
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user