From: Jason Gunthorpe <jgg@ziepe.ca>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Haowen Bai <baihaowen@meizu.com>,
Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>,
Leon Romanovsky <leon@kernel.org>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RDMA: remove null check after call container_of()
Date: Tue, 17 May 2022 15:03:03 -0300 [thread overview]
Message-ID: <20220517180303.GK63055@ziepe.ca> (raw)
In-Reply-To: <142a9c03-574f-adcf-bc4d-bb2a25c01e88@wanadoo.fr>
On Tue, May 17, 2022 at 07:54:38PM +0200, Christophe JAILLET wrote:
> Le 17/05/2022 à 14:16, Jason Gunthorpe a écrit :
> > On Tue, May 17, 2022 at 09:33:28AM +0800, Haowen Bai wrote:
> > > container_of() will never return NULL, so remove useless code.
> >
> > It is confusing here, but it can be null.
>
> Hi,
>
> out of curiosity, can you elaborate how it can be NULL?
It is guarented/required that that container_of is a 0 offset. The
normal usage of the ib_alloc_device macro:
#define ib_alloc_device(drv_struct, member) \
container_of(_ib_alloc_device(sizeof(struct drv_struct) + \
BUILD_BUG_ON_ZERO(offsetof( \
struct drv_struct, member))), \
struct drv_struct, member)
Enforces this property with a BUILD_BUG_ON
So, if the input pointer to container_of is reliably NULL or ERR_PTR
then the output pointer will be the same.
The rvt code here open codes the call because it is a mid-layer and
the sizeof() calculation above is not correct for it.
Jason
next prev parent reply other threads:[~2022-05-17 18:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-17 1:33 Haowen Bai
2022-05-17 12:16 ` Jason Gunthorpe
2022-05-17 17:54 ` Christophe JAILLET
2022-05-17 18:03 ` Jason Gunthorpe [this message]
2022-05-17 19:42 ` Christophe JAILLET
2022-05-18 1:55 ` baihaowen
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=20220517180303.GK63055@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=baihaowen@meizu.com \
--cc=christophe.jaillet@wanadoo.fr \
--cc=dennis.dalessandro@cornelisnetworks.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
/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
all inboxes | Powered by JetHome®