Skip to content

Commit 10fd7fb

Browse files
committed
nvme: tcp: split controller bringup handling
Drivers must call nvme_uninit_ctrl after a successful nvme_init_ctrl. Split the allocation side out to make the error handling boundary easier to navigate. The nvme tcp driver's error handling had different returns in the error goto label's, which harm readability. Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent b9ecbfa commit 10fd7fb

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

drivers/nvme/host/tcp.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,7 @@ nvme_tcp_existing_controller(struct nvmf_ctrl_options *opts)
26862686
return found;
26872687
}
26882688

2689-
static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev,
2689+
static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,
26902690
struct nvmf_ctrl_options *opts)
26912691
{
26922692
struct nvme_tcp_ctrl *ctrl;
@@ -2761,6 +2761,24 @@ static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev,
27612761
if (ret)
27622762
goto out_kfree_queues;
27632763

2764+
return ctrl;
2765+
out_kfree_queues:
2766+
kfree(ctrl->queues);
2767+
out_free_ctrl:
2768+
kfree(ctrl);
2769+
return ERR_PTR(ret);
2770+
}
2771+
2772+
static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev,
2773+
struct nvmf_ctrl_options *opts)
2774+
{
2775+
struct nvme_tcp_ctrl *ctrl;
2776+
int ret;
2777+
2778+
ctrl = nvme_tcp_alloc_ctrl(dev, opts);
2779+
if (IS_ERR(ctrl))
2780+
return ERR_CAST(ctrl);
2781+
27642782
if (!nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_CONNECTING)) {
27652783
WARN_ON_ONCE(1);
27662784
ret = -EINTR;
@@ -2786,11 +2804,6 @@ static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev,
27862804
if (ret > 0)
27872805
ret = -EIO;
27882806
return ERR_PTR(ret);
2789-
out_kfree_queues:
2790-
kfree(ctrl->queues);
2791-
out_free_ctrl:
2792-
kfree(ctrl);
2793-
return ERR_PTR(ret);
27942807
}
27952808

27962809
static struct nvmf_transport_ops nvme_tcp_transport = {

0 commit comments

Comments
 (0)