]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: simplify lookup when builtin.modinfo.bin file is missing
authorLucas De Marchi <lucas.demarchi@intel.com>
Tue, 10 Mar 2020 05:00:26 +0000 (22:00 -0700)
committerLucas De Marchi <lucas.demarchi@intel.com>
Mon, 23 Mar 2020 19:37:26 +0000 (12:37 -0700)
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.

libkmod/libkmod-module.c
libkmod/libkmod.c

index 714ee217a69f08774ccd2fcdcdf1dcad657b362f..76a6dc30930f7195cd486aef109ca8683112cb2e 100644 (file)
@@ -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);
index c9d9e2a218ab81913395655d3833c5f63ff13410..39f58d9c558eb104e5e1e28e619cd1b5210d949c 100644 (file)
@@ -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;