Skip to content

Commit 04c41bf

Browse files
Christoph Hellwigdledford
authored andcommitted
IB/core: refactor ib_create_qp
Split the XRC magic into a separate function, and return early on failure to make the initialization code readable. Signed-off-by: Christoph Hellwig <[email protected]> Tested-by: Steve Wise <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Steve Wise <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent 002516e commit 04c41bf

File tree

1 file changed

+54
-49
lines changed

1 file changed

+54
-49
lines changed

drivers/infiniband/core/verbs.c

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -723,62 +723,67 @@ struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
723723
}
724724
EXPORT_SYMBOL(ib_open_qp);
725725

726+
static struct ib_qp *ib_create_xrc_qp(struct ib_qp *qp,
727+
struct ib_qp_init_attr *qp_init_attr)
728+
{
729+
struct ib_qp *real_qp = qp;
730+
731+
qp->event_handler = __ib_shared_qp_event_handler;
732+
qp->qp_context = qp;
733+
qp->pd = NULL;
734+
qp->send_cq = qp->recv_cq = NULL;
735+
qp->srq = NULL;
736+
qp->xrcd = qp_init_attr->xrcd;
737+
atomic_inc(&qp_init_attr->xrcd->usecnt);
738+
INIT_LIST_HEAD(&qp->open_list);
739+
740+
qp = __ib_open_qp(real_qp, qp_init_attr->event_handler,
741+
qp_init_attr->qp_context);
742+
if (!IS_ERR(qp))
743+
__ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp);
744+
else
745+
real_qp->device->destroy_qp(real_qp);
746+
return qp;
747+
}
748+
726749
struct ib_qp *ib_create_qp(struct ib_pd *pd,
727750
struct ib_qp_init_attr *qp_init_attr)
728751
{
729-
struct ib_qp *qp, *real_qp;
730-
struct ib_device *device;
752+
struct ib_device *device = pd ? pd->device : qp_init_attr->xrcd->device;
753+
struct ib_qp *qp;
731754

732-
device = pd ? pd->device : qp_init_attr->xrcd->device;
733755
qp = device->create_qp(pd, qp_init_attr, NULL);
734-
735-
if (!IS_ERR(qp)) {
736-
qp->device = device;
737-
qp->real_qp = qp;
738-
qp->uobject = NULL;
739-
qp->qp_type = qp_init_attr->qp_type;
740-
741-
atomic_set(&qp->usecnt, 0);
742-
if (qp_init_attr->qp_type == IB_QPT_XRC_TGT) {
743-
qp->event_handler = __ib_shared_qp_event_handler;
744-
qp->qp_context = qp;
745-
qp->pd = NULL;
746-
qp->send_cq = qp->recv_cq = NULL;
747-
qp->srq = NULL;
748-
qp->xrcd = qp_init_attr->xrcd;
749-
atomic_inc(&qp_init_attr->xrcd->usecnt);
750-
INIT_LIST_HEAD(&qp->open_list);
751-
752-
real_qp = qp;
753-
qp = __ib_open_qp(real_qp, qp_init_attr->event_handler,
754-
qp_init_attr->qp_context);
755-
if (!IS_ERR(qp))
756-
__ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp);
757-
else
758-
real_qp->device->destroy_qp(real_qp);
759-
} else {
760-
qp->event_handler = qp_init_attr->event_handler;
761-
qp->qp_context = qp_init_attr->qp_context;
762-
if (qp_init_attr->qp_type == IB_QPT_XRC_INI) {
763-
qp->recv_cq = NULL;
764-
qp->srq = NULL;
765-
} else {
766-
qp->recv_cq = qp_init_attr->recv_cq;
767-
atomic_inc(&qp_init_attr->recv_cq->usecnt);
768-
qp->srq = qp_init_attr->srq;
769-
if (qp->srq)
770-
atomic_inc(&qp_init_attr->srq->usecnt);
771-
}
772-
773-
qp->pd = pd;
774-
qp->send_cq = qp_init_attr->send_cq;
775-
qp->xrcd = NULL;
776-
777-
atomic_inc(&pd->usecnt);
778-
atomic_inc(&qp_init_attr->send_cq->usecnt);
779-
}
756+
if (IS_ERR(qp))
757+
return qp;
758+
759+
qp->device = device;
760+
qp->real_qp = qp;
761+
qp->uobject = NULL;
762+
qp->qp_type = qp_init_attr->qp_type;
763+
764+
atomic_set(&qp->usecnt, 0);
765+
if (qp_init_attr->qp_type == IB_QPT_XRC_TGT)
766+
return ib_create_xrc_qp(qp, qp_init_attr);
767+
768+
qp->event_handler = qp_init_attr->event_handler;
769+
qp->qp_context = qp_init_attr->qp_context;
770+
if (qp_init_attr->qp_type == IB_QPT_XRC_INI) {
771+
qp->recv_cq = NULL;
772+
qp->srq = NULL;
773+
} else {
774+
qp->recv_cq = qp_init_attr->recv_cq;
775+
atomic_inc(&qp_init_attr->recv_cq->usecnt);
776+
qp->srq = qp_init_attr->srq;
777+
if (qp->srq)
778+
atomic_inc(&qp_init_attr->srq->usecnt);
780779
}
781780

781+
qp->pd = pd;
782+
qp->send_cq = qp_init_attr->send_cq;
783+
qp->xrcd = NULL;
784+
785+
atomic_inc(&pd->usecnt);
786+
atomic_inc(&qp_init_attr->send_cq->usecnt);
782787
return qp;
783788
}
784789
EXPORT_SYMBOL(ib_create_qp);

0 commit comments

Comments
 (0)