All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "Michal Suchánek" <msuchanek@suse.de>,
	"SF Markus Elfring" <elfring@users.sourceforge.net>,
	linuxppc-dev@lists.ozlabs.org,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Alexey Kardashevskiy" <aik@ozlabs.ru>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Bart Van Assche" <bart.vanassche@sandisk.com>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"Doug Ledford" <dledford@redhat.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Johan Hovold" <johan@kernel.org>,
	"Masahiro Yamada" <yamada.masahiro@socionext.com>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Nathan Fontenot" <nfont@linux.vnet.ibm.com>,
	"Paul Mackerras" <paulus@samba.org>,
	"Rob Herring" <robh@kernel.org>,
	"Sahil Mehta" <sahilmehta17@gmail.com>,
	"Tyrel Datwyler" <tyreld@linux.vnet.ibm.com>,
	kernel-janitors@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_allo
Date: Fri, 20 Oct 2017 01:06:24 +0000	[thread overview]
Message-ID: <20171020010624.GE13245@umbus> (raw)
In-Reply-To: <20171019125558.itidc4ejr6goadci@mwanda>

[-- Attachment #1: Type: text/plain, Size: 2796 bytes --]

On Thu, Oct 19, 2017 at 03:55:59PM +0300, Dan Carpenter wrote:
> On Thu, Oct 19, 2017 at 01:37:18PM +0200, Michal Suchánek wrote:
> > Hello,
> > 
> > On Wed, 18 Oct 2017 21:24:25 +0200
> > SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> > 
> > > From: Markus Elfring <elfring@users.sourceforge.net>
> > > Date: Wed, 18 Oct 2017 19:14:39 +0200
> > > 
> > > The variable "table_group" will be set to an appropriate pointer.
> > > Thus omit the explicit initialisation at the beginning.
> > > 
> > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> > > ---
> > >  arch/powerpc/platforms/pseries/iommu.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/powerpc/platforms/pseries/iommu.c
> > > b/arch/powerpc/platforms/pseries/iommu.c index
> > > b37d4fb20d1c..b6c12b8e3ace 100644 ---
> > > a/arch/powerpc/platforms/pseries/iommu.c +++
> > > b/arch/powerpc/platforms/pseries/iommu.c @@ -55,7 +55,7 @@
> > >  
> > >  static struct iommu_table_group *iommu_pseries_alloc_group(int node)
> > >  {
> > > -	struct iommu_table_group *table_group = NULL;
> > > +	struct iommu_table_group *table_group;
> > >  	struct iommu_table *tbl = NULL;
> > >  	struct iommu_table_group_link *tgl = NULL;
> > >  
> > 
> > I think initializing pointers to NULL is generally a good idea.
> > 
> > If there is no use of the variable before it is reinitialized by
> > allocation gcc is free to optimize out the variable and its initial
> > value.
> > 
> > On the other hand, if the code is changed later and use of the variable
> > becomes possible you may crash (and get a gcc warning, too).
> 
> No, it's the opposite. GCC doesn't warn about potential NULL
> dereferences, it warns about uninitialized variables.  By initializing
> it to a bogus value, you're deliberately disabling static analysis.
> We do see bugs where, if only people didn't initialize stuff to bogus
> values, then the bug would have been caught before it was merged.

Seconded, I've seen this a number of times.  I think this alone is a
reason not to initiaize locals if they don't require it.
 
> You might imagine that static analysis tools would catch NULL
> dereferences but it's actually really really hard.  We used to have
> an __uninitialized_var() macro which was used to silence GCC false
> positives, but now we initialize the pointers to NULL instead.  So
> most of the code that you're dealing with is stuff that was marked as
> too hard for GCC to understand.  It's tricky.
> 
> regards,
> dan carpenter
> 
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

WARNING: multiple messages have this Message-ID (diff)
From: David Gibson <david@gibson.dropbear.id.au>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: "Michal Suchánek" <msuchanek@suse.de>,
	"SF Markus Elfring" <elfring@users.sourceforge.net>,
	linuxppc-dev@lists.ozlabs.org,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Alexey Kardashevskiy" <aik@ozlabs.ru>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Bart Van Assche" <bart.vanassche@sandisk.com>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"Doug Ledford" <dledford@redhat.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Johan Hovold" <johan@kernel.org>,
	"Masahiro Yamada" <yamada.masahiro@socionext.com>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Nathan Fontenot" <nfont@linux.vnet.ibm.com>,
	"Paul Mackerras" <paulus@samba.org>,
	"Rob Herring" <robh@kernel.org>,
	"Sahil Mehta" <sahilmehta17@gmail.com>,
	"Tyrel Datwyler" <tyreld@linux.vnet.ibm.com>,
	kernel-janitors@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_alloc_group()
Date: Fri, 20 Oct 2017 12:06:24 +1100	[thread overview]
Message-ID: <20171020010624.GE13245@umbus> (raw)
In-Reply-To: <20171019125558.itidc4ejr6goadci@mwanda>

[-- Attachment #1: Type: text/plain, Size: 2796 bytes --]

On Thu, Oct 19, 2017 at 03:55:59PM +0300, Dan Carpenter wrote:
> On Thu, Oct 19, 2017 at 01:37:18PM +0200, Michal Suchánek wrote:
> > Hello,
> > 
> > On Wed, 18 Oct 2017 21:24:25 +0200
> > SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> > 
> > > From: Markus Elfring <elfring@users.sourceforge.net>
> > > Date: Wed, 18 Oct 2017 19:14:39 +0200
> > > 
> > > The variable "table_group" will be set to an appropriate pointer.
> > > Thus omit the explicit initialisation at the beginning.
> > > 
> > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> > > ---
> > >  arch/powerpc/platforms/pseries/iommu.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/arch/powerpc/platforms/pseries/iommu.c
> > > b/arch/powerpc/platforms/pseries/iommu.c index
> > > b37d4fb20d1c..b6c12b8e3ace 100644 ---
> > > a/arch/powerpc/platforms/pseries/iommu.c +++
> > > b/arch/powerpc/platforms/pseries/iommu.c @@ -55,7 +55,7 @@
> > >  
> > >  static struct iommu_table_group *iommu_pseries_alloc_group(int node)
> > >  {
> > > -	struct iommu_table_group *table_group = NULL;
> > > +	struct iommu_table_group *table_group;
> > >  	struct iommu_table *tbl = NULL;
> > >  	struct iommu_table_group_link *tgl = NULL;
> > >  
> > 
> > I think initializing pointers to NULL is generally a good idea.
> > 
> > If there is no use of the variable before it is reinitialized by
> > allocation gcc is free to optimize out the variable and its initial
> > value.
> > 
> > On the other hand, if the code is changed later and use of the variable
> > becomes possible you may crash (and get a gcc warning, too).
> 
> No, it's the opposite. GCC doesn't warn about potential NULL
> dereferences, it warns about uninitialized variables.  By initializing
> it to a bogus value, you're deliberately disabling static analysis.
> We do see bugs where, if only people didn't initialize stuff to bogus
> values, then the bug would have been caught before it was merged.

Seconded, I've seen this a number of times.  I think this alone is a
reason not to initiaize locals if they don't require it.
 
> You might imagine that static analysis tools would catch NULL
> dereferences but it's actually really really hard.  We used to have
> an __uninitialized_var() macro which was used to silence GCC false
> positives, but now we initialize the pointers to NULL instead.  So
> most of the code that you're dealing with is stuff that was marked as
> too hard for GCC to understand.  It's tricky.
> 
> regards,
> dan carpenter
> 
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2017-10-20  1:06 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18 19:20 [PATCH 0/5] PowerPC-pSeries: Adjustments for seven function implementations SF Markus Elfring
2017-10-18 19:20 ` SF Markus Elfring
2017-10-18 19:21 ` [PATCH 1/5] powerpc-pseries: Delete five error messages for a failed memory allocation SF Markus Elfring
2017-10-18 19:21   ` SF Markus Elfring
2017-10-18 19:23 ` [PATCH 2/5] powerpc-pseries: Improve nine size determinations SF Markus Elfring
2017-10-18 19:23   ` SF Markus Elfring
2017-10-18 19:24 ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_alloc_gr SF Markus Elfring
2017-10-18 19:24   ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_alloc_group() SF Markus Elfring
2017-10-19 11:37   ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_allo Michal Suchánek
2017-10-19 11:37     ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_alloc_group() Michal Suchánek
2017-10-19 11:49     ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_allo SF Markus Elfring
2017-10-19 11:49       ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_alloc_group() SF Markus Elfring
2017-10-19 12:55     ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_allo Dan Carpenter
2017-10-19 12:55       ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_alloc_group() Dan Carpenter
2017-10-19 13:51       ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_allo Michal Suchánek
2017-10-19 13:51         ` [PATCH 3/5] powerpc-pseries: Delete an unnecessary variable initialisation in iommu_pseries_alloc_group() Michal Suchánek
2017-10-19 13:51         ` Michal Suchánek
2017-10-20  1:06       ` David Gibson [this message]
2017-10-20  1:06         ` David Gibson
2017-10-18 19:26 ` [PATCH 4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_alloc_gr SF Markus Elfring
2017-10-18 19:26   ` [PATCH 4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_alloc_group() SF Markus Elfring
2017-10-19 11:41   ` [PATCH 4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_allo Michal Suchánek
2017-10-19 11:41     ` [PATCH 4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_alloc_group() Michal Suchánek
2017-10-19 12:04     ` [PATCH 4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_allo SF Markus Elfring
2017-10-19 12:04       ` [PATCH 4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_alloc_group() SF Markus Elfring
2017-10-19 12:39       ` [PATCH 4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_allo Michal Suchánek
2017-10-19 12:39         ` [PATCH 4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_alloc_group() Michal Suchánek
2017-10-19 12:39         ` Michal Suchánek
2017-10-24  8:09   ` [4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_alloc_grou Michael Ellerman
2017-10-24  8:09     ` [4/5] powerpc-pseries: Return directly after a failed kzalloc_node() in iommu_pseries_alloc_group() Michael Ellerman
2017-10-18 19:27 ` [PATCH 5/5] powerpc-pseries: Less function calls in iommu_pseries_alloc_group() after error detectio SF Markus Elfring
2017-10-18 19:27   ` [PATCH 5/5] powerpc-pseries: Less function calls in iommu_pseries_alloc_group() after error detection SF Markus Elfring

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=20171020010624.GE13245@umbus \
    --to=david@gibson.dropbear.id.au \
    --cc=aik@ozlabs.ru \
    --cc=akpm@linux-foundation.org \
    --cc=alex.williamson@redhat.com \
    --cc=bart.vanassche@sandisk.com \
    --cc=benh@kernel.crashing.org \
    --cc=dan.carpenter@oracle.com \
    --cc=dledford@redhat.com \
    --cc=elfring@users.sourceforge.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=msuchanek@suse.de \
    --cc=nfont@linux.vnet.ibm.com \
    --cc=paulus@samba.org \
    --cc=robh@kernel.org \
    --cc=sahilmehta17@gmail.com \
    --cc=tyreld@linux.vnet.ibm.com \
    --cc=yamada.masahiro@socionext.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.