]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
tools/depmod: explicitly return ENOMEM on hash_new() failure
authorEmil Velikov <emil.l.velikov@gmail.com>
Wed, 4 Jun 2025 16:16:25 +0000 (17:16 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Wed, 11 Jun 2025 13:03:26 +0000 (08:03 -0500)
The function will always set errno of ENOMEM, so we might as well use
that. Making the code more consistent and removing a few bytes/LoC.

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

index 9883d79fca9e430d9bae98b11ca2ce4bf52a7529..9b0a9cd9ea8420ee48b4707904f2b6398214d838 100644 (file)
@@ -1034,30 +1034,22 @@ static void symbol_free(void *data)
 
 static int depmod_init(struct depmod *depmod, struct cfg *cfg, struct kmod_ctx *ctx)
 {
-       int err = 0;
-
        depmod->cfg = cfg;
        depmod->ctx = ctx;
 
        array_init(&depmod->modules, 128);
 
        depmod->modules_by_uncrelpath = hash_new(512, NULL);
-       if (depmod->modules_by_uncrelpath == NULL) {
-               err = -errno;
+       if (depmod->modules_by_uncrelpath == NULL)
                goto modules_by_uncrelpath_failed;
-       }
 
        depmod->modules_by_name = hash_new(512, NULL);
-       if (depmod->modules_by_name == NULL) {
-               err = -errno;
+       if (depmod->modules_by_name == NULL)
                goto modules_by_name_failed;
-       }
 
        depmod->symbols = hash_new(2048, symbol_free);
-       if (depmod->symbols == NULL) {
-               err = -errno;
+       if (depmod->symbols == NULL)
                goto symbols_failed;
-       }
 
        return 0;
 
@@ -1066,7 +1058,7 @@ symbols_failed:
 modules_by_name_failed:
        hash_free(depmod->modules_by_uncrelpath);
 modules_by_uncrelpath_failed:
-       return err;
+       return -ENOMEM;
 }
 
 static void depmod_shutdown(struct depmod *depmod)