]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
plugins/intel: fix logic errors
authorHannes Reinecke <hare@suse.de>
Fri, 22 Apr 2022 10:37:22 +0000 (12:37 +0200)
committerHannes Reinecke <hare@suse.de>
Fri, 22 Apr 2022 10:37:22 +0000 (12:37 +0200)
Fixup some logic errors found by coverity.

Signed-off-by: Hannes Reinecke <hare@suse.de>
plugins/intel/intel-nvme.c

index 2fae63bd6afbfa49d2969562a0d70c9f417d5593..73008840203e103c7026f735fc170e5d11dfd5bf 100644 (file)
@@ -1108,21 +1108,19 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct
                       sizeof(struct intel_lat_stats));
        }
 
-       if (!err) {
-               if (cfg.json)
-                       json_lat_stats(cfg.write);
-               else if (!cfg.raw_binary)
-                       show_lat_stats(cfg.write);
-               else {
-                       if (media_version[0] == 1000)
-                               d_raw((unsigned char *)&v1000_stats,
-                                     sizeof(v1000_stats));
-                       else
-                               d_raw((unsigned char *)&stats,
-                                     sizeof(stats));
-               }
-       } else if (err > 0)
-               nvme_show_status(err);
+       if (cfg.json)
+               json_lat_stats(cfg.write);
+       else if (!cfg.raw_binary)
+               show_lat_stats(cfg.write);
+       else {
+               if (media_version[0] == 1000)
+                       d_raw((unsigned char *)&v1000_stats,
+                             sizeof(v1000_stats));
+               else
+                       d_raw((unsigned char *)&stats,
+                             sizeof(stats));
+       }
+
 close_fd:
        close(fd);
        return err;
@@ -1388,14 +1386,14 @@ static int get_internal_log(int argc, char **argv, struct command *command,
        }
 
        if (cfg.log > 2 || cfg.core > 4 || cfg.lnum > 255) {
-               free(intel);
-               return EINVAL;
+               err = -EINVAL;
+               goto out_free;
        }
 
        if (!cfg.file) {
                err = setup_file(f, cfg.file, fd, cfg.log);
                if (err)
-                       goto out;
+                       goto out_free;
                cfg.file = f;
        }
 
@@ -1406,6 +1404,10 @@ static int get_internal_log(int argc, char **argv, struct command *command,
        cdlog.u.fields.selectNlog = cfg.lnum < 0 ? 0 : cfg.lnum;
 
        output = open(cfg.file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+       if (output < 0) {
+               err = output;
+               goto out_free;
+       }
 
        err = read_header(&cmd, buf, fd, cdlog.u.entireDword, cfg.namespace_id);
        if (err)
@@ -1497,7 +1499,7 @@ static int get_internal_log(int argc, char **argv, struct command *command,
                }
        }
        err = 0;
- out:
+out:
        if (err > 0) {
                nvme_show_status(err);
        } else if (err < 0) {