All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Weihang Li <liweihang@huawei.com>
Cc: <dledford@redhat.com>, <leon@kernel.org>,
	<linux-rdma@vger.kernel.org>, <linuxarm@huawei.com>
Subject: Re: [PATCH for-next] RDMA/hns: Refactor the hns_roce_buf allocation flow
Date: Thu, 12 Nov 2020 12:01:06 -0400	[thread overview]
Message-ID: <20201112160106.GA894521@nvidia.com> (raw)
In-Reply-To: <1603967462-18124-1-git-send-email-liweihang@huawei.com>

On Thu, Oct 29, 2020 at 06:31:02PM +0800, Weihang Li wrote:
>  	/* The minimum shift of the page accessed by hw is HNS_HW_PAGE_SHIFT */
> -	buf->page_shift = max_t(int, HNS_HW_PAGE_SHIFT, page_shift);
> +	WARN_ON(page_shift < HNS_HW_PAGE_SHIFT);

Stuff like this should be written as

  if (WARN_ON(page_shift < HNS_HW_PAGE_SHIFT))
    return ERR_PTR(-EINVAL);

Rather than wrongly continuing on

> @@ -780,19 +769,16 @@ static int mtr_alloc_bufs(struct hns_roce_dev *hr_dev, struct hns_roce_mtr *mtr,
>  		ret = 0;
>  	} else {
>  		mtr->umem = NULL;
> -		mtr->kmem = kzalloc(sizeof(*mtr->kmem), GFP_KERNEL);
> -		if (!mtr->kmem) {
> -			ibdev_err(ibdev, "Failed to alloc kmem\n");
> +		mtr->kmem =
> +			hns_roce_buf_alloc(hr_dev, total_size,
> +					   buf_attr->page_shift,
> +					   is_direct ? HNS_ROCE_BUF_DIRECT : 0);
> +		if (IS_ERR_OR_NULL(mtr->kmem)) {

Please do not use IS_ERR_OR_NULL

Routines should not return NULL and an error pointer, one or the other
- or NULL needs to have special meaning and is not an error.

> +			ibdev_err(ibdev, "failed to alloc kmem, ret = %ld.\n",
> +				  PTR_ERR(mtr->kmem));
>  			return -ENOMEM;

Here you should return PTR_ERR((mtr->kmem)

In other places in this driver too, please check all the
IS_ERR_OR_NULL's

Jason

  reply	other threads:[~2020-11-12 16:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29 10:31 [PATCH for-next] RDMA/hns: Refactor the hns_roce_buf allocation flow Weihang Li
2020-11-12 16:01 ` Jason Gunthorpe [this message]
2020-11-13  9:25   ` liweihang

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=20201112160106.GA894521@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=dledford@redhat.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=liweihang@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.