]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
intel-nvme: Fix compiler errors and warnings
authorKeith Busch <keith.busch@intel.com>
Mon, 23 Oct 2017 19:13:01 +0000 (13:13 -0600)
committerKeith Busch <keith.busch@intel.com>
Mon, 23 Oct 2017 19:21:27 +0000 (13:21 -0600)
This initializes the intel log specific structures to offsets from
dynamically allocated structure to avoid gcc casting errors.

Signed-off-by: Keith Busch <keith.busch@intel.com>
intel-nvme.c

index ca4d2449ba566cb88fea1a85edc173f4c17fd9de..7678eb320e7fe7e8581af3f68e70c8110f211a35 100644 (file)
@@ -639,11 +639,11 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
        char f[0x100];
        int err, fd, output, i, j, count = 0, core_num = 1;//, remainder;
        struct nvme_passthru_cmd cmd;
-       static struct intel_vu_log intel;
-       struct intel_assert_dump *ad;
-       struct intel_vu_nlog *intel_nlog;
-       struct intel_event_header *ehdr;
-
+       struct intel_cd_log cdlog;
+       struct intel_vu_log *intel = malloc(sizeof(struct intel_vu_log));
+       struct intel_vu_nlog *intel_nlog = (struct intel_vu_nlog *)buf;
+       struct intel_assert_dump *ad = (struct intel_assert_dump *) intel->reserved;
+       struct intel_event_header *ehdr = (struct intel_event_header *)intel->reserved;
 
        char *desc = "Get Intel Firmware Log and save it.";
        char *log = "Log type: 0, 1, or 2 for nlog, event log, and assert log, respectively.";
@@ -669,8 +669,6 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
                .core = -1
        };
 
-       struct intel_cd_log cdlog;
-
        const struct argconfig_commandline_options command_line_options[] = {
                {"log",          'l', "NUM",  CFG_POSITIVE, &cfg.log,          required_argument, log},
                {"region",       'r', "NUM",  CFG_INT, &cfg.core,         required_argument, core},
@@ -692,8 +690,7 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
                cfg.file = f;
        }
 
-       memset(&cdlog, 0, sizeof(cdlog));
-       memset(&intel_nlog, 0, sizeof(intel_nlog));
+       cdlog.u.entireDword = 0;
 
        cdlog.u.fields.selectLog = cfg.log;
        cdlog.u.fields.selectCore = cfg.core < 0 ? 0 : cfg.core;
@@ -704,13 +701,12 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
        err = read_header(&cmd, buf, fd, cdlog.u.entireDword, cfg.namespace_id);
        if (err)
                goto out;
-
-       memcpy(&intel, buf, sizeof(intel));
-       cmd.addr = (unsigned long)(void *)buf;
+       memcpy(intel, buf, sizeof(*intel));
 
        /* for 1.1 Fultondales will use old nlog, but current assert/event */
-       if ((intel.ver.major < 1 && intel.ver.minor < 1) ||
-           (intel.ver.major <= 1 && intel.ver.minor <= 1 && cfg.log == 0)) {
+       if ((intel->ver.major < 1 && intel->ver.minor < 1) ||
+           (intel->ver.major <= 1 && intel->ver.minor <= 1 && cfg.log == 0)) {
+               cmd.addr = (unsigned long)(void *)buf;
                err = get_internal_log_old(buf, output, fd, &cmd);
                goto out;
        }
@@ -718,8 +714,8 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
        if (cfg.log == 2) {
                if (cfg.verbose)
                        printf("Log major:%d minor:%d header:%d size:%d numcores:%d\n",
-                              intel.ver.major, intel.ver.minor, intel.header, intel.size,
-                              intel.numcores);
+                              intel->ver.major, intel->ver.minor, intel->header, intel->size,
+                              intel->numcores);
 
                err = write_header(buf, output, 0x1000);
                if (err) {
@@ -727,10 +723,8 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
                        goto out;
                }
 
-               count = intel.numcores;
-               ad = (void *) intel.reserved;
-       } else if (!cfg.log) {
-               intel_nlog = (void*)buf;
+               count = intel->numcores;
+       } else if (cfg.log == 0) {
                if (cfg.lnum < 0)
                        count = intel_nlog->totalnlogs;
                else
@@ -738,10 +732,9 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
                if (cfg.core < 0)
                        core_num = intel_nlog->corecount;
        } else if (cfg.log == 1) {
-               ehdr = (void *) intel.reserved;
-               core_num = intel.numcores;
+               core_num = intel->numcores;
                count = 1;
-               err = write_header(buf, output, sizeof(intel));
+               err = write_header(buf, output, sizeof(*intel));
                if (err)
                        goto out;
        }
@@ -749,7 +742,9 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
        for (j = (cfg.core < 0 ? 0 : cfg.core); j < (cfg.core < 0 ? core_num : cfg.core + 1); j++) {
                cdlog.u.fields.selectCore = j;
                for (i = 0; i < count; i++) {
-                       if (cfg.log == 0 && ad[i].assertvalid) {
+                       if (cfg.log == 2) {
+                               if (!ad[i].assertvalid)
+                                       continue;
                                cmd.cdw13 = ad[i].coreoffset;
                                cmd.cdw10 = 0x400;
                                cmd.data_len = min(0x400, ad[i].assertsize) * 4;
@@ -758,12 +753,13 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
                                if (err)
                                        goto out;
 
-                       } else if(!cfg.log) {
+                       } else if(cfg.log == 0) {
                                /* If the user selected to read the entire nlog */
                                if (count > 1)
                                        cdlog.u.fields.selectNlog = i;
 
-                               err = read_header(&cmd, buf, fd, cdlog.u.entireDword, cfg.namespace_id);
+                               err = read_header(&cmd, buf, fd, cdlog.u.entireDword,
+                                               cfg.namespace_id);
                                if (err)
                                        goto out;
                                err = write_header(buf, output, sizeof(*intel_nlog));
@@ -774,7 +770,7 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
                                cmd.cdw13 = 0x400;
                                cmd.cdw10 = 0x400;
                                cmd.data_len = min(0x1000, intel_nlog->nlogbytesize);
-                               err = read_entire_cmd(&cmd, intel_nlog->nlogbytesize/4,
+                               err = read_entire_cmd(&cmd, intel_nlog->nlogbytesize / 4,
                                                      0x400, output, fd, buf);
                                if (err)
                                        goto out;
@@ -799,6 +795,7 @@ static int get_internal_log(int argc, char **argv, struct command *command, stru
                err = EIO;
        } else
                printf("Successfully wrote log to %s\n", cfg.file);
+       free(intel);
        return err;
 
 }