]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
wdc: Update file parameter checking
authorDong Ho <Dong.Ho@wdc.com>
Mon, 4 Feb 2019 19:54:05 +0000 (19:54 +0000)
committerKeith Busch <keith.busch@intel.com>
Wed, 6 Feb 2019 00:46:43 +0000 (17:46 -0700)
plugins/wdc/wdc-nvme.c

index 2f9a541a5c6460a37f65972bfbeec0f5f8dccc63..99ca5bd11e82efbbed22904be8901baf61fddf4d 100644 (file)
@@ -1154,15 +1154,6 @@ static int wdc_do_cap_diag(int fd, char *file, __u32 xfer_size)
        __u32 e6_log_hdr_size = WDC_NVME_CAP_DIAG_HEADER_TOC_SIZE;
        struct wdc_e6_log_hdr *log_hdr;
        __u32 cap_diag_length;
-       int verify_file;
-
-       /* verify the passed in file name and path is valid before getting the dump data */
-       verify_file = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-       if (verify_file < 0) {
-               fprintf(stderr, "ERROR : WDC: open : %s\n", strerror(errno));
-               return -1;
-       }
-       close(verify_file);
 
        log_hdr = (struct wdc_e6_log_hdr *) malloc(e6_log_hdr_size);
        if (log_hdr == NULL) {
@@ -1608,6 +1599,15 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *command
        }
 
        if (cfg.file != NULL) {
+               int verify_file;
+
+               /* verify the passed in file name and path is valid before getting the dump data */
+               verify_file = open(cfg.file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+               if (verify_file < 0) {
+                       fprintf(stderr, "ERROR : WDC: open : %s\n", strerror(errno));
+                       return -1;
+               }
+               close(verify_file);
                strncpy(f, cfg.file, PATH_MAX - 1);
        } else {
                wdc_UtilsGetTime(&timeInfo);