All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Niels Dossche <dossche.niels@gmail.com>
Cc: cgel.zte@gmail.com, dennis.dalessandro@cornelisnetworks.com,
	jgg@ziepe.ca, linux-rdma@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Minghao Chi <chi.minghao@zte.com.cn>,
	Zeal Robot <zealci@zte.com.cn>
Subject: Re: [PATCH] infiniband: remove unnecessary null check
Date: Wed, 24 Aug 2022 14:51:26 +0300	[thread overview]
Message-ID: <YwYQvm48ReVaFQ0v@unreal> (raw)
In-Reply-To: <1ce29a1e-2db7-2953-b71e-c0408559ecff@gmail.com>

On Wed, Aug 24, 2022 at 10:15:56AM +0200, Niels Dossche wrote:
> On 8/24/22 10:05, cgel.zte@gmail.com wrote:
> > From: Minghao Chi <chi.minghao@zte.com.cn>
> > 
> > container_of is never null, so this null check is
> > unnecessary.
> > 
> > Reported-by: Zeal Robot <zealci@zte.com.cn>
> > Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn>
> > ---
> >  drivers/infiniband/sw/rdmavt/vt.c | 2 --
> >  1 file changed, 2 deletions(-)
> > 
> > diff --git a/drivers/infiniband/sw/rdmavt/vt.c b/drivers/infiniband/sw/rdmavt/vt.c
> > index 59481ae39505..b2d83b4958fc 100644
> > --- a/drivers/infiniband/sw/rdmavt/vt.c
> > +++ b/drivers/infiniband/sw/rdmavt/vt.c
> > @@ -50,8 +50,6 @@ struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)
> >  	struct rvt_dev_info *rdi;
> >  
> >  	rdi = container_of(_ib_alloc_device(size), struct rvt_dev_info, ibdev);
> > -	if (!rdi)
> > -		return rdi;
> >  
> >  	rdi->ports = kcalloc(nports, sizeof(*rdi->ports), GFP_KERNEL);
> >  	if (!rdi->ports)
> 
> I believe this patch is incorrect because "_ib_alloc_device" may return a null pointer.
> Note that the first member of "rvt_dev_info" is "ib_device", so the check on container_of effectively checks if the allocation failed, which is necessary to check.

You are absolutely right, this container_of() and check later are done
on purpose. It is open-coded variant of ib_alloc_device(...) macro.

Thanks

      reply	other threads:[~2022-08-24 11:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24  8:05 [PATCH] infiniband: remove unnecessary null check cgel.zte
2022-08-24  8:15 ` Niels Dossche
2022-08-24 11:51   ` Leon Romanovsky [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=YwYQvm48ReVaFQ0v@unreal \
    --to=leon@kernel.org \
    --cc=cgel.zte@gmail.com \
    --cc=chi.minghao@zte.com.cn \
    --cc=dennis.dalessandro@cornelisnetworks.com \
    --cc=dossche.niels@gmail.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=zealci@zte.com.cn \
    /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.