]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: return bool from lookup_builtin_file()
authorEmil Velikov <emil.l.velikov@gmail.com>
Mon, 4 Nov 2024 14:32:39 +0000 (14:32 +0000)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 7 Nov 2024 19:43:49 +0000 (13:43 -0600)
The callers are interested if the file is within the list of builtins or
not. So change the return type and push the free() down the stack.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/224
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
libkmod/libkmod.c

index 611e7475adcd91c18b6ce611a5e6ed327d2d7eb6..cd6c8948114d58cd181f3704680c4226a3aa2d2f 100644 (file)
@@ -445,9 +445,13 @@ static char *lookup_file(struct kmod_ctx *ctx, enum kmod_index index_number,
        return line;
 }
 
-static char *lookup_builtin_file(struct kmod_ctx *ctx, const char *name)
+static bool lookup_builtin_file(struct kmod_ctx *ctx, const char *name)
 {
-       return lookup_file(ctx, KMOD_INDEX_MODULES_BUILTIN, name);
+       char *line = lookup_file(ctx, KMOD_INDEX_MODULES_BUILTIN, name);
+       bool found = line != NULL;
+
+       free(line);
+       return found;
 }
 
 int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx, const char *name,
@@ -472,20 +476,17 @@ int kmod_lookup_alias_from_kernel_builtin_file(struct kmod_ctx *ctx, const char
 int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name,
                                        struct kmod_list **list)
 {
-       char *line;
-       int err = 0;
-
        assert(*list == NULL);
 
-       line = lookup_builtin_file(ctx, name);
-       if (line != NULL) {
+       if (lookup_builtin_file(ctx, name)) {
                struct kmod_module *mod;
+               int err;
 
                err = kmod_module_new_from_name(ctx, name, &mod);
                if (err < 0) {
                        ERR(ctx, "Could not create module from name %s: %s\n", name,
                            strerror(-err));
-                       goto finish;
+                       return err;
                }
 
                /* already mark it as builtin since it's being created from
@@ -493,21 +494,15 @@ int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name,
                kmod_module_set_builtin(mod, true);
                *list = kmod_list_append(*list, mod);
                if (*list == NULL)
-                       err = -ENOMEM;
+                       return -ENOMEM;
        }
 
-finish:
-       free(line);
-       return err;
+       return 0;
 }
 
 bool kmod_lookup_alias_is_builtin(struct kmod_ctx *ctx, const char *name)
 {
-       _cleanup_free_ char *line;
-
-       line = lookup_builtin_file(ctx, name);
-
-       return line != NULL;
+       return lookup_builtin_file(ctx, name);
 }
 
 char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name)