]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/core/kmod-setup.c
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / core / kmod-setup.c
index 066b959770e20611dac5b06b43b884bf83026dce..0550e222b577427f56b43e55cb7574ea9a6c062d 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
   This file is part of systemd.
 
@@ -31,6 +32,7 @@
 #include "fileio.h"
 #include "kmod-setup.h"
 #include "macro.h"
+#include "module-util.h"
 #include "string-util.h"
 
 #if HAVE_KMOD
@@ -110,7 +112,7 @@ int kmod_setup(void) {
                 /* virtio_rng would be loaded by udev later, but real entropy might be needed very early */
                 { "virtio_rng", NULL,                       false,  false,   has_virtio_rng },
         };
-        struct kmod_ctx *ctx = NULL;
+        _cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL;
         unsigned int i;
         int r;
 
@@ -118,7 +120,7 @@ int kmod_setup(void) {
                 return 0;
 
         for (i = 0; i < ELEMENTSOF(kmod_table); i++) {
-                struct kmod_module *mod;
+                _cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;
 
                 if (kmod_table[i].path && access(kmod_table[i].path, F_OK) >= 0)
                         continue;
@@ -157,13 +159,8 @@ int kmod_setup(void) {
                         log_full_errno(print_warning ? LOG_WARNING : LOG_DEBUG, r,
                                        "Failed to insert module '%s': %m", kmod_module_get_name(mod));
                 }
-
-                kmod_module_unref(mod);
         }
 
-        if (ctx)
-                kmod_unref(ctx);
-
 #endif
         return 0;
 }