nvme-tcp: Add warning on state change failure at nvme_tcp_setup_ctrl
authorIsrael Rukshin <israelr@mellanox.com>
Tue, 24 Mar 2020 15:29:45 +0000 (17:29 +0200)
committerKeith Busch <kbusch@kernel.org>
Wed, 25 Mar 2020 19:51:56 +0000 (04:51 +0900)
The transition to LIVE state should not fail in case of a new controller.
Moving to DELETING state before nvme_tcp_create_ctrl() allocates all the
resources may leads to NULL dereference at teardown flow (e.g., IO tagset,
admin_q, connect_q).

Signed-off-by: Israel Rukshin <israelr@mellanox.com>
Reviewed-by: Max Gurtovoy <maxg@mellanox.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
drivers/nvme/host/tcp.c

index f111430bb6178824941f97858b33fee397cff43f..0ef14f0fad863216236a1358f6d73bf8f696d4f3 100644 (file)
@@ -1930,8 +1930,13 @@ static int nvme_tcp_setup_ctrl(struct nvme_ctrl *ctrl, bool new)
        }
 
        if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_LIVE)) {
-               /* state change failure is ok if we're in DELETING state */
+               /*
+                * state change failure is ok if we're in DELETING state,
+                * unless we're during creation of a new controller to
+                * avoid races with teardown flow.
+                */
                WARN_ON_ONCE(ctrl->state != NVME_CTRL_DELETING);
+               WARN_ON_ONCE(new);
                ret = -EINVAL;
                goto destroy_io;
        }