[PATCH 3/6] libkmod: simplify lookup when builtin.modinfo.bin file is missing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 |  8 ++++----
 libkmod/libkmod.c        | 25 +++++++++++--------------
 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;
-- 
2.25.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux