Skip to content

Commit 72cded7

Browse files
committed
nvme: fc: 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 fc 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 ea47c47 commit 72cded7

File tree

1 file changed

+27
-16
lines changed
  • drivers/nvme/host

1 file changed

+27
-16
lines changed

drivers/nvme/host/fc.c

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,12 +3444,11 @@ nvme_fc_existing_controller(struct nvme_fc_rport *rport,
34443444
return found;
34453445
}
34463446

3447-
static struct nvme_ctrl *
3448-
nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
3447+
static struct nvme_fc_ctrl *
3448+
nvme_fc_alloc_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
34493449
struct nvme_fc_lport *lport, struct nvme_fc_rport *rport)
34503450
{
34513451
struct nvme_fc_ctrl *ctrl;
3452-
unsigned long flags;
34533452
int ret, idx, ctrl_loss_tmo;
34543453

34553454
if (!(rport->remoteport.port_role &
@@ -3538,7 +3537,31 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
35383537
if (lport->dev)
35393538
ctrl->ctrl.numa_node = dev_to_node(lport->dev);
35403539

3541-
/* at this point, teardown path changes to ref counting on nvme ctrl */
3540+
return ctrl;
3541+
3542+
out_free_queues:
3543+
kfree(ctrl->queues);
3544+
out_free_ida:
3545+
put_device(ctrl->dev);
3546+
ida_free(&nvme_fc_ctrl_cnt, ctrl->cnum);
3547+
out_free_ctrl:
3548+
kfree(ctrl);
3549+
out_fail:
3550+
/* exit via here doesn't follow ctlr ref points */
3551+
return ERR_PTR(ret);
3552+
}
3553+
3554+
static struct nvme_ctrl *
3555+
nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
3556+
struct nvme_fc_lport *lport, struct nvme_fc_rport *rport)
3557+
{
3558+
struct nvme_fc_ctrl *ctrl;
3559+
unsigned long flags;
3560+
int ret;
3561+
3562+
ctrl = nvme_fc_alloc_ctrl(dev, opts, lport, rport);
3563+
if (IS_ERR(ctrl))
3564+
return ERR_CAST(ctrl);
35423565

35433566
ret = nvme_alloc_admin_tag_set(&ctrl->ctrl, &ctrl->admin_tag_set,
35443567
&nvme_fc_admin_mq_ops,
@@ -3597,20 +3620,8 @@ nvme_fc_init_ctrl(struct device *dev, struct nvmf_ctrl_options *opts,
35973620
nvme_fc_rport_get(rport);
35983621

35993622
return ERR_PTR(-EIO);
3600-
3601-
out_free_queues:
3602-
kfree(ctrl->queues);
3603-
out_free_ida:
3604-
put_device(ctrl->dev);
3605-
ida_free(&nvme_fc_ctrl_cnt, ctrl->cnum);
3606-
out_free_ctrl:
3607-
kfree(ctrl);
3608-
out_fail:
3609-
/* exit via here doesn't follow ctlr ref points */
3610-
return ERR_PTR(ret);
36113623
}
36123624

3613-
36143625
struct nvmet_fc_traddr {
36153626
u64 nn;
36163627
u64 pn;

0 commit comments

Comments
 (0)