]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nvmet-rdma: Fix NULL deref when setting pi_enable and traddr INADDR_ANY
authorIsrael Rukshin <israelr@nvidia.com>
Sun, 10 Jan 2021 12:09:05 +0000 (14:09 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 14 Jan 2021 19:27:34 +0000 (20:27 +0100)
When setting port traddr to INADDR_ANY, the listening cm_id->device
is NULL. The associate IB device is known only when a connect request
event arrives, so checking T10-PI device capability should be done
at this stage.

Fixes: bd69ae64e6b6 ("nvmet-rdma: add metadata/T10-PI support")
Signed-off-by: Israel Rukshin <israelr@nvidia.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/rdma.c

index bdfc22eb2a10fa95847411b047a4e0ea9a2f676a..06b6b742bb213e3ba924ef113d81e4081379b2be 100644 (file)
@@ -1220,6 +1220,14 @@ nvmet_rdma_find_get_device(struct rdma_cm_id *cm_id)
        }
        ndev->inline_data_size = nport->inline_data_size;
        ndev->inline_page_count = inline_page_count;
+
+       if (nport->pi_enable && !(cm_id->device->attrs.device_cap_flags &
+                                 IB_DEVICE_INTEGRITY_HANDOVER)) {
+               pr_warn("T10-PI is not supported by device %s. Disabling it\n",
+                       cm_id->device->name);
+               nport->pi_enable = false;
+       }
+
        ndev->device = cm_id->device;
        kref_init(&ndev->ref);
 
@@ -1855,14 +1863,6 @@ static int nvmet_rdma_enable_port(struct nvmet_rdma_port *port)
                goto out_destroy_id;
        }
 
-       if (port->nport->pi_enable &&
-           !(cm_id->device->attrs.device_cap_flags &
-             IB_DEVICE_INTEGRITY_HANDOVER)) {
-               pr_err("T10-PI is not supported for %pISpcs\n", addr);
-               ret = -EINVAL;
-               goto out_destroy_id;
-       }
-
        port->cm_id = cm_id;
        return 0;