IB/usnic: Simplify the code to balance loc/unlock calls
authorLeon Romanovsky <leon@kernel.org>
Sat, 22 Apr 2017 14:28:51 +0000 (17:28 +0300)
committerDoug Ledford <dledford@redhat.com>
Fri, 28 Apr 2017 17:11:43 +0000 (13:11 -0400)
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: Leon Romanovsky <leon@kernel.org>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/hw/usnic/usnic_ib_verbs.c

index bcd6f7b1c634d78542c05a854b8a7828ba7538b8..44a93326f7b52ce5f7d1e6111a1c6cd491c9b3f0 100644 (file)
@@ -152,7 +152,7 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev,
        struct usnic_vnic *vnic;
        struct usnic_ib_qp_grp *qp_grp;
        struct device *dev, **dev_list;
-       int i, found = 0;
+       int i;
 
        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,
                                                us_ibdev->ib_dev.name,
                                                pci_name(usnic_vnic_get_pdev(
                                                                        vnic)));
-                               found = 1;
-                               break;
+                               qp_grp = usnic_ib_qp_grp_create(us_ibdev->ufdev,
+                                                               vf, pd,
+                                                               res_spec,
+                                                               trans_spec);
+
+                               spin_unlock(&vf->lock);
+                               goto qp_grp_check;
                        }
                        spin_unlock(&vf->lock);
 
@@ -183,34 +188,30 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev,
                usnic_uiom_free_dev_list(dev_list);
        }
 
-       if (!found) {
-               /* Try to find resources on an unused vf */
-               list_for_each_entry(vf, &us_ibdev->vf_dev_list, link) {
-                       spin_lock(&vf->lock);
-                       vnic = vf->vnic;
-                       if (vf->qp_grp_ref_cnt == 0 &&
-                               usnic_vnic_check_room(vnic, res_spec) == 0) {
-                               found = 1;
-                               break;
-                       }
+       /* Try to find resources on an unused vf */
+       list_for_each_entry(vf, &us_ibdev->vf_dev_list, link) {
+               spin_lock(&vf->lock);
+               vnic = vf->vnic;
+               if (vf->qp_grp_ref_cnt == 0 &&
+                   usnic_vnic_check_room(vnic, res_spec) == 0) {
+                       qp_grp = usnic_ib_qp_grp_create(us_ibdev->ufdev, vf,
+                                                       pd, res_spec,
+                                                       trans_spec);
+
                        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);
-               return ERR_PTR(-ENOMEM);
-       }
+       usnic_info("No free qp grp found on %s\n", us_ibdev->ib_dev.name);
+       return ERR_PTR(-ENOMEM);
 
-       qp_grp = usnic_ib_qp_grp_create(us_ibdev->ufdev, vf, pd, res_spec,
-                                               trans_spec);
-       spin_unlock(&vf->lock);
+qp_grp_check:
        if (IS_ERR_OR_NULL(qp_grp)) {
                usnic_err("Failed to allocate qp_grp\n");
                return ERR_PTR(qp_grp ? PTR_ERR(qp_grp) : -ENOMEM);
        }
-
        return qp_grp;
 }