Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Maoyi Xie <maoyixie.tju@gmail.com>
Cc: Chengchang Tang <tangchengchang@huawei.com>,
	Junxian Huang <huangjunxian6@hisilicon.com>,
	Leon Romanovsky <leon@kernel.org>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] RDMA/hns: drop dead empty check in setup_root_hem()
Date: Wed, 3 Jun 2026 15:16:02 -0300	[thread overview]
Message-ID: <20260603181602.GA1568873@nvidia.com> (raw)
In-Reply-To: <20260526054653.2054800-1-maoyixie.tju@gmail.com>

On Tue, May 26, 2026 at 01:46:53PM +0800, Maoyi Xie wrote:
> setup_root_hem() reads the first entry of head->root and checks
> the returned pointer against NULL:
> 
>     root_hem = list_first_entry(&head->root,
>                                 struct hns_roce_hem_item, list);
>     if (!root_hem)
>         return -ENOMEM;
> 
> list_first_entry() never returns NULL. On an empty list it returns
> container_of(head, ..., list), a non-NULL garbage pointer that
> aliases the head. So the check is dead.
> 
> The only caller adds an entry to head.root right before invoking
> setup_root_hem():
> 
>     list_add(&root_hem->list, &head.root);
>     ret = setup_root_hem(..., &head, ...);
> 
> So head.root is guaranteed non-empty on entry. Drop the check.
> 
> Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
> Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
> ---
> v2: drop the check entirely per Jason's review, instead of
>     converting to list_first_entry_or_null() as in v1.
> v1: https://lore.kernel.org/r/20260521132045.3430906-1-maoyixie.tju@gmail.com
> 
>  drivers/infiniband/hw/hns/hns_roce_hem.c | 2 --
>  1 file changed, 2 deletions(-)

Applied to for-next, thanks

Jason

      reply	other threads:[~2026-06-03 18:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 13:20 [PATCH] RDMA/hns: fix dead empty check on head->root in setup_root_hem() Maoyi Xie
2026-05-25 15:51 ` Jason Gunthorpe
2026-05-26  5:46 ` [PATCH v2] RDMA/hns: drop dead empty check " Maoyi Xie
2026-06-03 18:16   ` Jason Gunthorpe [this message]

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=20260603181602.GA1568873@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=huangjunxian6@hisilicon.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=maoyixie.tju@gmail.com \
    --cc=tangchengchang@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