]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: use cleanup helper for STREAM objects
authorDaniel Wagner <dwagner@suse.de>
Thu, 4 Jul 2024 16:38:56 +0000 (18:38 +0200)
committerDaniel Wagner <wagi@monom.org>
Tue, 9 Jul 2024 09:29:47 +0000 (11:29 +0200)
The tls_key function is using a STREAM object and closes it when leaving
the context. Update it to use the helper.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
nvme.c

diff --git a/nvme.c b/nvme.c
index 6ce7f12e833177cb2f8040af12e008c5b0ef58d8..0c18f4e1956b98dcfaf50e7e39aa731f95cb1c44 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -9446,7 +9446,7 @@ static int tls_key(int argc, char **argv, struct command *command, struct plugin
        const char *import = "Import all keys into the keyring.";
        const char *export = "Export all keys from the keyring.";
 
-       FILE *fd;
+       _cleanup_file_ FILE *fd = NULL;
        int err = 0;
 
        struct config {
@@ -9499,7 +9499,7 @@ static int tls_key(int argc, char **argv, struct command *command, struct plugin
 
        if (cfg.export && cfg.import) {
                nvme_show_error("Cannot specify both --import and --export");
-               err = -EINVAL;
+               return -EINVAL;
        } else if (cfg.export) {
                nvme_scan_tls_keys(cfg.keyring, __scan_tls_key, fd);
        } else if (cfg.import) {
@@ -9513,8 +9513,7 @@ static int tls_key(int argc, char **argv, struct command *command, struct plugin
                keyring_id = nvme_lookup_keyring(cfg.keyring);
                if (!keyring_id) {
                        nvme_show_error("Invalid keyring '%s'", cfg.keyring);
-                       err = -ENOKEY;
-                       goto out;
+                       return -ENOKEY;
                }
 
                while (fgets(tls_str, 512, fd)) {
@@ -9543,10 +9542,6 @@ static int tls_key(int argc, char **argv, struct command *command, struct plugin
                err = -EINVAL;
        }
 
-out:
-       if (cfg.keyfile)
-               fclose(fd);
-
        return err;
 }