driver inclusion category: cleanup bugzilla: https://gitee.com/openeuler/kernel/issues/I6GT7F
--------------------------------------------------------------------------
The code of the current free mr abnormal branch is not readable, resulting in false positives when checked by tools such as smatch.
This patch combines the processing of exception branches into a separate function to improve readability.
Signed-off-by: Chengchang Tang tangchengchang@huawei.com --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 42 ++++++++++++++-------- 1 file changed, 28 insertions(+), 14 deletions(-)
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 69f969b7773b..c631ca4b9567 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -2850,6 +2850,19 @@ static struct ib_pd *free_mr_init_pd(struct hns_roce_dev *hr_dev) return pd; }
+static void free_mr_uninit_pd(struct hns_roce_dev *hr_dev) +{ + struct hns_roce_v2_priv *priv = hr_dev->priv; + struct hns_roce_v2_free_mr *free_mr = &priv->free_mr; + + if (!free_mr->rsv_pd) + return; + + hns_roce_dealloc_pd(&free_mr->rsv_pd->ibpd, NULL); + kvfree(free_mr->rsv_pd); + free_mr->rsv_pd = NULL; +} + static struct ib_cq *free_mr_init_cq(struct hns_roce_dev *hr_dev) { struct hns_roce_v2_priv *priv = hr_dev->priv; @@ -2887,6 +2900,19 @@ static struct ib_cq *free_mr_init_cq(struct hns_roce_dev *hr_dev) return cq; }
+static void free_mr_uninit_cq(struct hns_roce_dev *hr_dev) +{ + struct hns_roce_v2_priv *priv = hr_dev->priv; + struct hns_roce_v2_free_mr *free_mr = &priv->free_mr; + + if (!free_mr->rsv_cq) + return; + + hns_roce_destroy_cq(&free_mr->rsv_cq->ib_cq, NULL); + kvfree(free_mr->rsv_cq); + free_mr->rsv_cq = NULL; +} + static struct hns_roce_qp *create_free_mr_qp(struct hns_roce_dev *hr_dev, struct ib_pd *pd, struct ib_cq *cq) { @@ -2932,16 +2958,6 @@ static void free_mr_exit(struct hns_roce_dev *hr_dev) } }
- if (free_mr->rsv_cq) { - hns_roce_destroy_cq(&free_mr->rsv_cq->ib_cq, NULL); - kfree(free_mr->rsv_cq); - } - - if (free_mr->rsv_pd) { - hns_roce_dealloc_pd(&free_mr->rsv_pd->ibpd, NULL); - free_mr->rsv_pd = NULL; - kfree(free_mr->rsv_pd); - } }
static int free_mr_alloc_res(struct hns_roce_dev *hr_dev) @@ -2976,12 +2992,10 @@ static int free_mr_alloc_res(struct hns_roce_dev *hr_dev) return 0;
create_failed_qp: - hns_roce_destroy_cq(cq, NULL); - kfree(cq); + free_mr_uninit_cq(hr_dev);
create_failed_cq: - hns_roce_dealloc_pd(pd, NULL); - kfree(pd); + free_mr_uninit_pd(hr_dev);
return ret; }