Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d5c1c03 authored by Yuval Avnery's avatar Yuval Avnery Committed by Greg Kroah-Hartman
Browse files

IB/core: Destroy QP if XRC QP fails



commit 535005ca8e5e71918d64074032f4b9d4fef8981e upstream.

The open-coded variant missed destroy of SELinux created QP, reuse already
existing ib_detroy_qp() call and use this opportunity to clean
ib_create_qp() from double prints and unclear exit paths.

Reported-by: default avatarParav Pandit <parav@mellanox.com>
Fixes: d291f1a6 ("IB/core: Enforce PKey security on QPs")
Signed-off-by: default avatarYuval Avnery <yuvalav@mellanox.com>
Reviewed-by: default avatarParav Pandit <parav@mellanox.com>
Reviewed-by: default avatarDaniel Jurgens <danielj@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 84148743
Loading
Loading
Loading
Loading
+24 −17
Original line number Original line Diff line number Diff line
@@ -1087,7 +1087,7 @@ struct ib_qp *ib_open_qp(struct ib_xrcd *xrcd,
}
}
EXPORT_SYMBOL(ib_open_qp);
EXPORT_SYMBOL(ib_open_qp);


static struct ib_qp *ib_create_xrc_qp(struct ib_qp *qp,
static struct ib_qp *create_xrc_qp(struct ib_qp *qp,
				   struct ib_qp_init_attr *qp_init_attr)
				   struct ib_qp_init_attr *qp_init_attr)
{
{
	struct ib_qp *real_qp = qp;
	struct ib_qp *real_qp = qp;
@@ -1103,10 +1103,10 @@ static struct ib_qp *ib_create_xrc_qp(struct ib_qp *qp,


	qp = __ib_open_qp(real_qp, qp_init_attr->event_handler,
	qp = __ib_open_qp(real_qp, qp_init_attr->event_handler,
			  qp_init_attr->qp_context);
			  qp_init_attr->qp_context);
	if (!IS_ERR(qp))
	if (IS_ERR(qp))
		return qp;

	__ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp);
	__ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp);
	else
		real_qp->device->destroy_qp(real_qp);
	return qp;
	return qp;
}
}


@@ -1137,10 +1137,8 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
		return qp;
		return qp;


	ret = ib_create_qp_security(qp, device);
	ret = ib_create_qp_security(qp, device);
	if (ret) {
	if (ret)
		ib_destroy_qp(qp);
		goto err;
		return ERR_PTR(ret);
	}


	qp->real_qp    = qp;
	qp->real_qp    = qp;
	qp->qp_type    = qp_init_attr->qp_type;
	qp->qp_type    = qp_init_attr->qp_type;
@@ -1153,8 +1151,15 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
	INIT_LIST_HEAD(&qp->sig_mrs);
	INIT_LIST_HEAD(&qp->sig_mrs);
	qp->port = 0;
	qp->port = 0;


	if (qp_init_attr->qp_type == IB_QPT_XRC_TGT)
	if (qp_init_attr->qp_type == IB_QPT_XRC_TGT) {
		return ib_create_xrc_qp(qp, qp_init_attr);
		struct ib_qp *xrc_qp = create_xrc_qp(qp, qp_init_attr);

		if (IS_ERR(xrc_qp)) {
			ret = PTR_ERR(xrc_qp);
			goto err;
		}
		return xrc_qp;
	}


	qp->event_handler = qp_init_attr->event_handler;
	qp->event_handler = qp_init_attr->event_handler;
	qp->qp_context = qp_init_attr->qp_context;
	qp->qp_context = qp_init_attr->qp_context;
@@ -1181,11 +1186,8 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,


	if (qp_init_attr->cap.max_rdma_ctxs) {
	if (qp_init_attr->cap.max_rdma_ctxs) {
		ret = rdma_rw_init_mrs(qp, qp_init_attr);
		ret = rdma_rw_init_mrs(qp, qp_init_attr);
		if (ret) {
		if (ret)
			pr_err("failed to init MR pool ret= %d\n", ret);
			goto err;
			ib_destroy_qp(qp);
			return ERR_PTR(ret);
		}
	}
	}


	/*
	/*
@@ -1198,6 +1200,11 @@ struct ib_qp *ib_create_qp(struct ib_pd *pd,
				 device->attrs.max_sge_rd);
				 device->attrs.max_sge_rd);


	return qp;
	return qp;

err:
	ib_destroy_qp(qp);
	return ERR_PTR(ret);

}
}
EXPORT_SYMBOL(ib_create_qp);
EXPORT_SYMBOL(ib_create_qp);