linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Doug Ledford <dledford@redhat.com>
To: Lijun Ou <oulijun@huawei.com>, jgg@ziepe.ca
Cc: linux-rdma@vger.kernel.org, linuxarm@huawei.com
Subject: Re: [PATCH for-next 2/9] RDMA/hns: Refactor the codes of creating qp
Date: Wed, 28 Aug 2019 11:19:18 -0400	[thread overview]
Message-ID: <e91d1e75aad3b283e3d232993b15c1bb33e522d7.camel@redhat.com> (raw)
In-Reply-To: <1566393276-42555-3-git-send-email-oulijun@huawei.com>

[-- Attachment #1: Type: text/plain, Size: 3535 bytes --]

On Wed, 2019-08-21 at 21:14 +0800, Lijun Ou wrote:
> +static int hns_roce_alloc_recv_inline_buffer(struct hns_roce_qp
> *hr_qp,
> +                                            struct ib_qp_init_attr
> *init_attr)
> +{
> +       int ret;
> +       int i;
> +
> +       /* allocate recv inline buf */
> +       hr_qp->rq_inl_buf.wqe_list = kcalloc(hr_qp->rq.wqe_cnt,
> +                                            sizeof(struct
> hns_roce_rinl_wqe),
> +                                            GFP_KERNEL);
> +       if (!hr_qp->rq_inl_buf.wqe_list) {
> +               ret = -ENOMEM;
> +               goto err;
> +       }
> +
> +       hr_qp->rq_inl_buf.wqe_cnt = hr_qp->rq.wqe_cnt;
> +
> +       /* Firstly, allocate a list of sge space buffer */
> +       hr_qp->rq_inl_buf.wqe_list[0].sg_list =
> +                                       kcalloc(hr_qp-
> >rq_inl_buf.wqe_cnt,
> +                                       init_attr->cap.max_recv_sge *
> +                                       sizeof(struct
> hns_roce_rinl_sge),
> +                                       GFP_KERNEL);
> +       if (!hr_qp->rq_inl_buf.wqe_list[0].sg_list) {
> +               ret = -ENOMEM;
> +               goto err_wqe_list;
> +       }
> +
> +       for (i = 1; i < hr_qp->rq_inl_buf.wqe_cnt; i++)
> +               /* Secondly, reallocate the buffer */
> +               hr_qp->rq_inl_buf.wqe_list[i].sg_list =
> +                                    &hr_qp-
> >rq_inl_buf.wqe_list[0].sg_list[i *
> +                                    init_attr->cap.max_recv_sge];
> +
> +       return 0;
> +
> +err_wqe_list:
> +       kfree(hr_qp->rq_inl_buf.wqe_list);
> +
> +err:
> +       return ret;
> +}

This function is klunky.  You don't need int ret; at all as there are
only two possible return values and you have distinct locations for each
return, so each return can use a constant.  It would be much more
readable like this:

+static int hns_roce_alloc_recv_inline_buffer(struct hns_roce_qp *hr_qp,
+                                            struct ib_qp_init_attr *init_attr)
+{
+	int num_sge = init_attr->cap.max_recv_sge;
+	int wqe_cnt = hr_qp->rq.wqe_cnt;
+       int i;
+
+       /* allocate recv inline WQE bufs */
+       hr_qp->rq_inl_buf.wqe_list = kcalloc(wqe_cnt,
+                                            sizeof(struct hns_roce_rinl_wqe),
+                                            GFP_KERNEL);
+       if (!hr_qp->rq_inl_buf.wqe_list)
+               goto err;
+
+       hr_qp->rq_inl_buf.wqe_cnt = wqe_cnt;
+
+       /* allocate a single sge array for all WQEs */
+       hr_qp->rq_inl_buf.wqe_list[0].sg_list =
+                                       kcalloc(wqe_cnt,
+                                       num_sge *
+                                       sizeof(struct hns_roce_rinl_sge),
+                                       GFP_KERNEL);
+       if (!hr_qp->rq_inl_buf.wqe_list[0].sg_list)
+               goto err_wqe_list;
+
+       for (i = 1; i < wqe_cnt; i++)
+               /* give each WQE a pointer to its array space */
+               hr_qp->rq_inl_buf.wqe_list[i].sg_list =
+                           &hr_qp->rq_inl_buf.wqe_list[0].sg_list[i * num_sge];
+
+       return 0;
+
+err_wqe_list:
+       kfree(hr_qp->rq_inl_buf.wqe_list);
+err:
+       return -ENOMEM;
+}

-- 
Doug Ledford <dledford@redhat.com>
    GPG KeyID: B826A3330E572FDD
    Fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-08-28 15:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-21 13:14 [PATCH for-next 0/9] Fixes for hip08 driver Lijun Ou
2019-08-21 13:14 ` [PATCH for-next 1/9] RDMA/hns: Refactor cmd init and mode selection for hip08 Lijun Ou
2019-08-21 17:19   ` Leon Romanovsky
2019-08-26  8:43     ` liweihang
2019-08-21 13:14 ` [PATCH for-next 2/9] RDMA/hns: Refactor the codes of creating qp Lijun Ou
2019-08-28 15:19   ` Doug Ledford [this message]
2019-08-29  0:56     ` oulijun
2019-08-21 13:14 ` [PATCH for-next 3/9] RDMA/hns: Modify the data structure of hns_roce_av Lijun Ou
2019-08-21 13:14 ` [PATCH for-next 4/9] RDMA/hns: Remove the some magic number Lijun Ou
2019-08-21 13:14 ` [PATCH for-next 5/9] RDMA/hns: Fix cast from or to restricted __le32 for driver Lijun Ou
2019-08-21 13:14 ` [PATCH for-next 6/9] RDMA/hns: Add reset process for function-clear Lijun Ou
2019-08-21 13:14 ` [PATCH for-next 7/9] RDMA/hns: Remove if-else judgment statements for creating srq Lijun Ou
2019-08-21 13:14 ` [PATCH for-next 8/9] RDMA/hns: Delete the not-used lines Lijun Ou
2019-08-21 13:14 ` [PATCH for-next 9/9] RDMA/hns: Fix wrong assignment of qp_access_flags Lijun Ou
2019-08-28 15:31 ` [PATCH for-next 0/9] Fixes for hip08 driver Doug Ledford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e91d1e75aad3b283e3d232993b15c1bb33e522d7.camel@redhat.com \
    --to=dledford@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=oulijun@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).