linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Raju Rangoju <rajur@chelsio.com>
Cc: Yang Li <abaci-bugfix@linux.alibaba.com>,
	davem@davemloft.net, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next] cxgb4: remove redundant NULL check
Date: Wed, 27 Jan 2021 13:13:53 -0800	[thread overview]
Message-ID: <20210127131353.5fc141da@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> (raw)
In-Reply-To: <20210127063426.GC21071@chelsio.com>

On Wed, 27 Jan 2021 12:04:27 +0530 Raju Rangoju wrote:
> On Tuesday, January 01/26/21, 2021 at 10:50:13 +0800, Yang Li wrote:
> > Fix below warnings reported by coccicheck:
> > ./drivers/net/ethernet/chelsio/cxgb4/clip_tbl.c:323:3-9: WARNING:
> > NULL check before some freeing functions is not needed.
> > ./drivers/net/ethernet/chelsio/cxgb4/cudbg_lib.c:3554:2-8: WARNING:
> > NULL check before some freeing functions is not needed.
> > ./drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c:157:2-7: WARNING:
> > NULL check before some freeing functions is not needed.
> > ./drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c:525:3-9: WARNING:
> > NULL check before some freeing functions is not needed.
> > 
> > Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> > Signed-off-by: Yang Li <abaci-bugfix@linux.alibaba.com>

> > diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c
> > index 77648e4..dd66b24 100644
> > --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c
> > +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_cudbg.c
> > @@ -157,8 +157,7 @@ static int cudbg_alloc_compress_buff(struct cudbg_init *pdbg_init)
> >  
> >  static void cudbg_free_compress_buff(struct cudbg_init *pdbg_init)
> >  {
> > -	if (pdbg_init->compress_buff)  
> 
> NAK. The above check is necessary.
> 
> pdbg_init->compress_buff may be NULL when Zlib is unavailable or when
> pdbg_init->compress_buff allocation fails, in which case we ignore error
> and continue without compression. Check is necessary before calling
> vfree().

Thanks taking a look! The point is that vfree() kfree() etc. all can be
fed NULL in which case they are a nop. E.g.:

/**
 * vfree - Release memory allocated by vmalloc()
 * @addr:  Memory base address
 *
 * Free the virtually continuous memory area starting at @addr, as obtained
 * from one of the vmalloc() family of APIs.  This will usually also free the
 * physical memory underlying the virtual allocation, but that memory is
 * reference counted, so it will not be freed until the last user goes away.
 *
   vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
>* If @addr is NULL, no operation is performed. <=
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 *
 * Context:
 * May sleep if called *not* from interrupt context.
 * Must not be called in NMI context (strictly speaking, it could be
 * if we have CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG, but making the calling
 * conventions for vfree() arch-depenedent would be a really bad idea).
 */

I don't think there is any advanced static analysis going on here if
that's what you assumed.

Yang, please respin, and explain in the patch message why removing
those conditions is safe.

      reply	other threads:[~2021-01-27 21:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26  2:50 [PATCH net-next] cxgb4: remove redundant NULL check Yang Li
2021-01-27  6:34 ` Raju Rangoju
2021-01-27 21:13   ` Jakub Kicinski [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=20210127131353.5fc141da@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com \
    --to=kuba@kernel.org \
    --cc=abaci-bugfix@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rajur@chelsio.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).