]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
lightnvm: fix type coercion
authorKeith Busch <keith.busch@intel.com>
Tue, 17 Jul 2018 21:56:25 +0000 (15:56 -0600)
committerKeith Busch <keith.busch@intel.com>
Tue, 17 Jul 2018 22:22:19 +0000 (16:22 -0600)
The lightnvm passthrough command wasn't actually aligned to the ioctl's
structure because it had an extra dword, and some compilers were having a
hard time dealing with some of the other structure casting. This fixes
the passthrough structure by removing the erroneous dword, and uses
temporary void pointers for type casting.

Link: https://github.com/linux-nvme/nvme-cli/issues/386
Signed-off-by: Keith Busch <keith.busch@intel.com>
nvme-lightnvm.c
nvme-lightnvm.h

index 465f4912147a2c285b212e75e623a84478800001..37bd24bff7fefa7e213582a9ca2dc874e5dcd3c1 100644 (file)
@@ -239,8 +239,9 @@ int lnvm_do_factory_init(char *devname, int erase_only_marked,
        return ret;
 }
 
-static void show_lnvm_id_grp(struct nvme_nvm_id12_group *grp, int human)
+static void show_lnvm_id_grp(void *t, int human)
 {
+       struct nvme_nvm_id12_group *grp = t;
        uint32_t mpos = (uint32_t)le32_to_cpu(grp->mpos);
        uint32_t mccap = (uint32_t)le32_to_cpu(grp->mccap);
 
@@ -329,13 +330,15 @@ static void show_lnvm_ppaf(struct nvme_nvm_addr_format *ppaf)
                                        ppaf->sect_offset, ppaf->sect_len);
 }
 
-static void show_lnvm_id12_ns(struct nvme_nvm_id12 *id, unsigned int flags)
+static void show_lnvm_id12_ns(void *t, unsigned int flags)
 {
        int i;
        int human = flags & HUMAN;
+       struct nvme_nvm_id12 *id = t;
 
        uint32_t cap = (uint32_t) le32_to_cpu(id->cap);
        uint32_t dom = (uint32_t) le32_to_cpu(id->dom);
+       uint32_t cgrps = id->cgrps;
 
        if (id->cgrps > 4) {
                fprintf(stderr, "invalid identify geometry returned\n");
@@ -368,9 +371,9 @@ static void show_lnvm_id12_ns(struct nvme_nvm_id12 *id, unsigned int flags)
        }
        show_lnvm_ppaf(&id->ppaf);
 
-       for (i = 0; i < id->cgrps; i++) {
+       for (i = 0; i < cgrps; i++) {
                printf("grp      : %d\n", i);
-               show_lnvm_id_grp(&id->groups[i], human);
+               show_lnvm_id_grp((void *)&id->groups[i], human);
        }
 }
 
@@ -419,14 +422,13 @@ static void show_lnvm_id20_ns(struct nvme_nvm_id20 *id, unsigned int flags)
 
 static void show_lnvm_id_ns(struct nvme_nvm_id *id, unsigned int flags)
 {
+       void *tmp = id;
        switch (id->ver_id) {
                case 1:
-                       show_lnvm_id12_ns((struct nvme_nvm_id12 *)id,
-                                       flags);
+                       show_lnvm_id12_ns(tmp, flags);
                break;
                case 2:
-                       show_lnvm_id20_ns((struct nvme_nvm_id20 *)id,
-                                       flags);
+                       show_lnvm_id20_ns(tmp, flags);
                break;
                default:
                        fprintf(stderr, "Version %d not supported.\n",
@@ -496,9 +498,10 @@ static int __lnvm_do_get_bbtbl(int fd, struct nvme_nvm_id12 *id,
                .data_len       = cpu_to_le32(bufsz),
                .ppa            = cpu_to_le64(ppa.ppa),
        };
+       void *tmp = &cmd;
+       struct nvme_passthru_cmd *nvme_cmd = tmp;
 
-       err = nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD,
-                                       (struct nvme_passthru_cmd *)&cmd);
+       err = nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD, nvme_cmd);
        if (err > 0) {
                fprintf(stderr, "NVMe Status:%s(%x)\n",
                        nvme_status_to_string(err), err);
@@ -522,8 +525,9 @@ int lnvm_do_get_bbtbl(int fd, int nsid, int lunid, int chid, unsigned int flags)
        struct nvme_nvm_id12 nvm_id;
        struct ppa_addr ppa;
        int err;
+       void *tmp = &nvm_id;
 
-       err = lnvm_get_identity(fd, nsid, (struct nvme_nvm_id *)&nvm_id);
+       err = lnvm_get_identity(fd, nsid, (struct nvme_nvm_id *)tmp);
        if (err) {
                fprintf(stderr, "NVMe Status:%s(%x)\n",
                        nvme_status_to_string(err), err);
@@ -562,9 +566,10 @@ static int __lnvm_do_set_bbtbl(int fd, struct ppa_addr ppa, __u8 value)
                .nlb            = cpu_to_le16(0),
                .value          = value,
        };
+       void *tmp = &cmd;
+       struct nvme_passthru_cmd *nvme_cmd = tmp;
 
-       err = nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD,
-                                       (struct nvme_passthru_cmd *)&cmd);
+       err = nvme_submit_passthru(fd, NVME_IOCTL_ADMIN_CMD, nvme_cmd);
        if (err > 0) {
                fprintf(stderr, "NVMe Status:%s(%x)\n",
                        nvme_status_to_string(err), err);
@@ -580,8 +585,9 @@ int lnvm_do_set_bbtbl(int fd, int nsid,
        struct nvme_nvm_id12 nvm_id;
        struct ppa_addr ppa;
        int err;
+       void *tmp = &nvm_id;
 
-       err = lnvm_get_identity(fd, nsid, (struct nvme_nvm_id *)&nvm_id);
+       err = lnvm_get_identity(fd, nsid, (struct nvme_nvm_id *)tmp);
        if (err) {
                fprintf(stderr, "NVMe Status:%s(%x)\n",
                        nvme_status_to_string(err), err);
index a13c0cf2cb9d1117dd4473273dc3cf6cb63f2052..9dea91262e76d44927b222b87598563cbc243463 100644 (file)
@@ -69,12 +69,11 @@ struct nvme_nvm_getbbtbl {
        __le32  nsid;
        __le32  cdw2;
        __le32  cdw3;
-       __le64  metadata;
+       __u64   metadata;
        __u64   addr;
-       __le32  metadata_len;
-       __le32  data_len;
+       __u32   metadata_len;
+       __u32   data_len;
        __le64  ppa;
-       __le32  cdw11;
        __le32  cdw12;
        __le32  cdw13;
        __le32  cdw14;