Message ID | 20220225112559.43300-8-liangwenpeng@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Jason Gunthorpe |
Headers | show |
Series | RDMA/hns: Clean up and refactor mailbox-related code | expand |
On Fri, Feb 25, 2022 at 07:25:57PM +0800, Wenpeng Liang wrote: > hns_roce_alloc_cmd_mailbox() never returns NULL, so the check should be > IS_ERR(). Additionally, PTR_ERR() should be used to return an error code. > > Signed-off-by: Wenpeng Liang <liangwenpeng@huawei.com> > --- > drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 4 ++-- > drivers/infiniband/hw/hns/hns_roce_mr.c | 8 +++----- > drivers/infiniband/hw/hns/hns_roce_srq.c | 4 ++-- > 3 files changed, 7 insertions(+), 9 deletions(-) > Thanks, Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
On Fri, Feb 25, 2022 at 07:25:57PM +0800, Wenpeng Liang wrote: > @@ -282,7 +280,7 @@ struct ib_mr *hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, > > mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); > if (IS_ERR(mailbox)) > - return ERR_CAST(mailbox); > + return ERR_PTR(mailbox); This doesn't compile, it should stay as ERR_CAST, right? Jason
On 2022/3/1 0:04, Jason Gunthorpe wrote: > On Fri, Feb 25, 2022 at 07:25:57PM +0800, Wenpeng Liang wrote: >> @@ -282,7 +280,7 @@ struct ib_mr *hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, >> >> mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); >> if (IS_ERR(mailbox)) >> - return ERR_CAST(mailbox); >> + return ERR_PTR(mailbox); > > This doesn't compile, it should stay as ERR_CAST, right? > > Jason > . > Yes, should keep using ERR_CAST, I missed the compile warning. Fix it in v3. Thanks, Wenpeng
diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 631f6e233492..06eb4f00428c 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -5981,8 +5981,8 @@ static int hns_roce_v2_create_eq(struct hns_roce_dev *hr_dev, /* Allocate mailbox memory */ mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); - if (IS_ERR_OR_NULL(mailbox)) - return -ENOMEM; + if (IS_ERR(mailbox)) + return PTR_ERR(mailbox); ret = alloc_eq_buf(hr_dev, eq); if (ret) diff --git a/drivers/infiniband/hw/hns/hns_roce_mr.c b/drivers/infiniband/hw/hns/hns_roce_mr.c index 39de862666d7..6184894bd897 100644 --- a/drivers/infiniband/hw/hns/hns_roce_mr.c +++ b/drivers/infiniband/hw/hns/hns_roce_mr.c @@ -148,10 +148,8 @@ static int hns_roce_mr_enable(struct hns_roce_dev *hr_dev, /* Allocate mailbox memory */ mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); - if (IS_ERR(mailbox)) { - ret = PTR_ERR(mailbox); - return ret; - } + if (IS_ERR(mailbox)) + return PTR_ERR(mailbox); if (mr->type != MR_TYPE_FRMR) ret = hr_dev->hw->write_mtpt(hr_dev, mailbox->buf, mr); @@ -282,7 +280,7 @@ struct ib_mr *hns_roce_rereg_user_mr(struct ib_mr *ibmr, int flags, u64 start, mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); if (IS_ERR(mailbox)) - return ERR_CAST(mailbox); + return ERR_PTR(mailbox); mtpt_idx = key_to_hw_index(mr->key) & (hr_dev->caps.num_mtpts - 1); diff --git a/drivers/infiniband/hw/hns/hns_roce_srq.c b/drivers/infiniband/hw/hns/hns_roce_srq.c index e316276e18c2..97032a357b00 100644 --- a/drivers/infiniband/hw/hns/hns_roce_srq.c +++ b/drivers/infiniband/hw/hns/hns_roce_srq.c @@ -89,9 +89,9 @@ static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) } mailbox = hns_roce_alloc_cmd_mailbox(hr_dev); - if (IS_ERR_OR_NULL(mailbox)) { + if (IS_ERR(mailbox)) { ibdev_err(ibdev, "failed to alloc mailbox for SRQC.\n"); - ret = -ENOMEM; + ret = PTR_ERR(mailbox); goto err_xa; }
hns_roce_alloc_cmd_mailbox() never returns NULL, so the check should be IS_ERR(). Additionally, PTR_ERR() should be used to return an error code. Signed-off-by: Wenpeng Liang <liangwenpeng@huawei.com> --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 4 ++-- drivers/infiniband/hw/hns/hns_roce_mr.c | 8 +++----- drivers/infiniband/hw/hns/hns_roce_srq.c | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-)