summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@intel.com>2020-03-09 22:00:26 -0700
committerLucas De Marchi <lucas.demarchi@intel.com>2020-03-23 12:37:26 -0700
commit89443220e3943624eba8e2e960c13c124e2082b8 (patch)
tree7a042aaae109bc1b3211496a932d15b0a4899847
parent53b30aeba2dedae9f5558f560231d9462e063dfc (diff)
downloadkmod-89443220e3943624eba8e2e960c13c124e2082b8.tar.gz
kmod-89443220e3943624eba8e2e960c13c124e2082b8.tar.bz2
kmod-89443220e3943624eba8e2e960c13c124e2082b8.zip
libkmod: simplify lookup when builtin.modinfo.bin file is missing
When we try to lookup a module and builtin.modinfo.bin is missing, we would do the right thing because the caller was replacing the return code with 0 (and the list was not modified). Make it simpler by allowing the caller to check and differentiate the errors between module not found and index not found.
-rw-r--r--libkmod/libkmod-module.c8
-rw-r--r--libkmod/libkmod.c25
2 files changed, 15 insertions, 18 deletions
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 714ee21..76a6dc3 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -577,13 +577,13 @@ KMOD_EXPORT int kmod_module_new_from_lookup(struct kmod_ctx *ctx,
DBG(ctx, "lookup modules.builtin.modinfo %s\n", alias);
err = kmod_lookup_alias_from_kernel_builtin_file(ctx, alias, list);
- CHECK_ERR_AND_FINISH(err, fail, list, finish);
-
- if (err == 0) {
+ if (err == -ENOSYS) {
+ /* Optional index missing, try the old one */
DBG(ctx, "lookup modules.builtin %s\n", alias);
err = kmod_lookup_alias_from_builtin_file(ctx, alias, list);
- CHECK_ERR_AND_FINISH(err, fail, list, finish);
}
+ CHECK_ERR_AND_FINISH(err, fail, list, finish);
+
finish:
DBG(ctx, "lookup %s=%d, list=%p\n", alias, err, *list);
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
index c9d9e2a..39f58d9 100644
--- a/libkmod/libkmod.c
+++ b/libkmod/libkmod.c
@@ -528,20 +528,17 @@ int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx,
struct kmod_list **list)
{
struct kmod_list *l;
- int ret = kmod_lookup_alias_from_alias_bin(ctx,
- KMOD_INDEX_MODULES_BUILTIN_ALIAS,
- name, list);
- if (ret > 0) {
- kmod_list_foreach(l, *list) {
- struct kmod_module *mod = l->data;
- kmod_module_set_builtin(mod, true);
- }
- } else if (ret == -ENOSYS) {
- /*
- * If the system does not support this yet, then
- * there is no need to return an error.
- */
- ret = 0;
+ int ret;
+
+ assert(*list == NULL);
+
+ ret = kmod_lookup_alias_from_alias_bin(ctx,
+ KMOD_INDEX_MODULES_BUILTIN_ALIAS,
+ name, list);
+
+ kmod_list_foreach(l, *list) {
+ struct kmod_module *mod = l->data;
+ kmod_module_set_builtin(mod, true);
}
return ret;