Commit 313e16d5 authored by Leon Romanovsky's avatar Leon Romanovsky Committed by Doug Ledford

IB/usnic: Simplify the code to balance loc/unlock calls

Simplify code in find_free_vf_and_create_qp_grp() to avoid sparse error
regarding call to unlock in the block other than lock was called.

drivers/infiniband/hw/usnic/usnic_ib_verbs.c:206:9: warning: context imbalance
			in 'find_free_vf_and_create_qp_grp' - different lock
			contexts for basic block

CC: Christian Benvenuti <benve@cisco.com>
Signed-off-by: default avatarLeon Romanovsky <leon@kernel.org>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent f5029e75
...@@ -152,7 +152,7 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev, ...@@ -152,7 +152,7 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev,
struct usnic_vnic *vnic; struct usnic_vnic *vnic;
struct usnic_ib_qp_grp *qp_grp; struct usnic_ib_qp_grp *qp_grp;
struct device *dev, **dev_list; struct device *dev, **dev_list;
int i, found = 0; int i;
BUG_ON(!mutex_is_locked(&us_ibdev->usdev_lock)); BUG_ON(!mutex_is_locked(&us_ibdev->usdev_lock));
...@@ -174,8 +174,13 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev, ...@@ -174,8 +174,13 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev,
us_ibdev->ib_dev.name, us_ibdev->ib_dev.name,
pci_name(usnic_vnic_get_pdev( pci_name(usnic_vnic_get_pdev(
vnic))); vnic)));
found = 1; qp_grp = usnic_ib_qp_grp_create(us_ibdev->ufdev,
break; vf, pd,
res_spec,
trans_spec);
spin_unlock(&vf->lock);
goto qp_grp_check;
} }
spin_unlock(&vf->lock); spin_unlock(&vf->lock);
...@@ -183,34 +188,30 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev, ...@@ -183,34 +188,30 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev,
usnic_uiom_free_dev_list(dev_list); usnic_uiom_free_dev_list(dev_list);
} }
if (!found) { /* Try to find resources on an unused vf */
/* Try to find resources on an unused vf */ list_for_each_entry(vf, &us_ibdev->vf_dev_list, link) {
list_for_each_entry(vf, &us_ibdev->vf_dev_list, link) { spin_lock(&vf->lock);
spin_lock(&vf->lock); vnic = vf->vnic;
vnic = vf->vnic; if (vf->qp_grp_ref_cnt == 0 &&
if (vf->qp_grp_ref_cnt == 0 && usnic_vnic_check_room(vnic, res_spec) == 0) {
usnic_vnic_check_room(vnic, res_spec) == 0) { qp_grp = usnic_ib_qp_grp_create(us_ibdev->ufdev, vf,
found = 1; pd, res_spec,
break; trans_spec);
}
spin_unlock(&vf->lock); spin_unlock(&vf->lock);
goto qp_grp_check;
} }
spin_unlock(&vf->lock);
} }
if (!found) { usnic_info("No free qp grp found on %s\n", us_ibdev->ib_dev.name);
usnic_info("No free qp grp found on %s\n", return ERR_PTR(-ENOMEM);
us_ibdev->ib_dev.name);
return ERR_PTR(-ENOMEM);
}
qp_grp = usnic_ib_qp_grp_create(us_ibdev->ufdev, vf, pd, res_spec, qp_grp_check:
trans_spec);
spin_unlock(&vf->lock);
if (IS_ERR_OR_NULL(qp_grp)) { if (IS_ERR_OR_NULL(qp_grp)) {
usnic_err("Failed to allocate qp_grp\n"); usnic_err("Failed to allocate qp_grp\n");
return ERR_PTR(qp_grp ? PTR_ERR(qp_grp) : -ENOMEM); return ERR_PTR(qp_grp ? PTR_ERR(qp_grp) : -ENOMEM);
} }
return qp_grp; return qp_grp;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment