]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
RDMA/usnic: Fix memleak in find_free_vf_and_create_qp_grp
authorDinghao Liu <dinghao.liu@zju.edu.cn>
Sat, 26 Dec 2020 07:42:48 +0000 (15:42 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 23 Jan 2021 14:36:55 +0000 (15:36 +0100)
commit a306aba9c8d869b1fdfc8ad9237f1ed718ea55e6 upstream.

If usnic_ib_qp_grp_create() fails at the first call, dev_list
will not be freed on error, which leads to memleak.

Fixes: e3cf00d0a87f ("IB/usnic: Add Cisco VIC low-level hardware driver")
Link: https://lore.kernel.org/r/20201226074248.2893-1-dinghao.liu@zju.edu.cn
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/infiniband/hw/usnic/usnic_ib_verbs.c

index 8e18bfca55166534c0c6314c462765d5cd341961..99d65f211b44b95b3ac4b76d288a71264095042e 100644 (file)
@@ -180,6 +180,7 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev,
 
                }
                usnic_uiom_free_dev_list(dev_list);
+               dev_list = NULL;
        }
 
        if (!found) {
@@ -207,6 +208,8 @@ find_free_vf_and_create_qp_grp(struct usnic_ib_dev *us_ibdev,
        spin_unlock(&vf->lock);
        if (IS_ERR_OR_NULL(qp_grp)) {
                usnic_err("Failed to allocate qp_grp\n");
+               if (usnic_ib_share_vf)
+                       usnic_uiom_free_dev_list(dev_list);
                return ERR_PTR(qp_grp ? PTR_ERR(qp_grp) : -ENOMEM);
        }