diff mbox

ahci: qoriq: fixed using uninitialized variable warnings

Message ID 1441790182-20248-1-git-send-email-Yuantian.Tang@freescale.com
State Not Applicable
Delegated to: David Miller
Headers show

Commit Message

tang yuantian Sept. 9, 2015, 9:16 a.m. UTC
From: Tang Yuantian <Yuantian.Tang@freescale.com>

kbuild test robot reports the warnings:
drivers/ata/ahci_qoriq.c: In function 'ahci_qoriq_hardreset':
>> include/asm-generic/io.h:163:2: warning: 'px_is' may be used
>> uninitialized in this function [-Wuninitialized]
drivers/ata/ahci_qoriq.c:70:14: note: 'px_is' was declared here
>> include/asm-generic/io.h:163:2: warning: 'px_cmd' may be used
>> uninitialized in this function [-Wuninitialized]
drivers/ata/ahci_qoriq.c:70:6: note: 'px_cmd' was declared here

This patch fixed it by assigning 0 to px_is and px_cmd variables.
This patch also remove line 'struct ccsr_ahci *reg_base' which is
not referred by any other codes and thus a dead one.

Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>
---
 drivers/ata/ahci_qoriq.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Hans de Goede Sept. 9, 2015, 10:57 a.m. UTC | #1
Hi,

On 09-09-15 11:16, Yuantian.Tang@freescale.com wrote:
> From: Tang Yuantian <Yuantian.Tang@freescale.com>
>
> kbuild test robot reports the warnings:
> drivers/ata/ahci_qoriq.c: In function 'ahci_qoriq_hardreset':
>>> include/asm-generic/io.h:163:2: warning: 'px_is' may be used
>>> uninitialized in this function [-Wuninitialized]
> drivers/ata/ahci_qoriq.c:70:14: note: 'px_is' was declared here
>>> include/asm-generic/io.h:163:2: warning: 'px_cmd' may be used
>>> uninitialized in this function [-Wuninitialized]
> drivers/ata/ahci_qoriq.c:70:6: note: 'px_cmd' was declared here
>
> This patch fixed it by assigning 0 to px_is and px_cmd variables.
> This patch also remove line 'struct ccsr_ahci *reg_base' which is
> not referred by any other codes and thus a dead one.
>
> Signed-off-by: Tang Yuantian <Yuantian.Tang@freescale.com>

LGTM: Acked-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> ---
>   drivers/ata/ahci_qoriq.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/ata/ahci_qoriq.c b/drivers/ata/ahci_qoriq.c
> index e5e4988..f790852 100644
> --- a/drivers/ata/ahci_qoriq.c
> +++ b/drivers/ata/ahci_qoriq.c
> @@ -49,7 +49,6 @@ enum ahci_qoriq_type {
>   };
>
>   struct ahci_qoriq_priv {
> -	struct ccsr_ahci *reg_base;
>   	enum ahci_qoriq_type type;
>   	void __iomem *ecc_addr;
>   };
> @@ -67,7 +66,7 @@ static int ahci_qoriq_hardreset(struct ata_link *link, unsigned int *class,
>   {
>   	const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
>   	void __iomem *port_mmio = ahci_port_base(link->ap);
> -	u32 px_cmd, px_is, px_val;
> +	u32 px_cmd = 0, px_is = 0, px_val;
>   	struct ata_port *ap = link->ap;
>   	struct ahci_port_priv *pp = ap->private_data;
>   	struct ahci_host_priv *hpriv = ap->host->private_data;
>
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tejun Heo Sept. 9, 2015, 2:01 p.m. UTC | #2
On Wed, Sep 09, 2015 at 05:16:22PM +0800, Yuantian.Tang@freescale.com wrote:
> From: Tang Yuantian <Yuantian.Tang@freescale.com>
> 
> kbuild test robot reports the warnings:
> drivers/ata/ahci_qoriq.c: In function 'ahci_qoriq_hardreset':
> >> include/asm-generic/io.h:163:2: warning: 'px_is' may be used
> >> uninitialized in this function [-Wuninitialized]
> drivers/ata/ahci_qoriq.c:70:14: note: 'px_is' was declared here
> >> include/asm-generic/io.h:163:2: warning: 'px_cmd' may be used
> >> uninitialized in this function [-Wuninitialized]
> drivers/ata/ahci_qoriq.c:70:6: note: 'px_cmd' was declared here
> 
> This patch fixed it by assigning 0 to px_is and px_cmd variables.
> This patch also remove line 'struct ccsr_ahci *reg_base' which is
> not referred by any other codes and thus a dead one.

Hmm... I think the problem here is that the complier can't know
whether qoriq_priv->type would change across intervening function
calls.  Maybe a better solution is caching the type in a local
variable so that the compiler can tell that those two tests will
always move together?  It generally isn't a good idea to clear
variables unnecessarily as that can hide actual bugs that compiler can
detect.

Thanks.
tang yuantian Sept. 10, 2015, 6:17 a.m. UTC | #3
> -----Original Message-----
> From: Tejun Heo [mailto:htejun@gmail.com] On Behalf Of Tejun Heo
> Sent: Wednesday, September 09, 2015 10:02 PM
> To: Tang Yuantian-B29983 <Yuantian.Tang@freescale.com>
> Cc: hdegoede@redhat.com; linux-ide@vger.kernel.org; linux-
> kernel@vger.kernel.org; devicetree@vger.kernel.org
> Subject: Re: [PATCH] ahci: qoriq: fixed using uninitialized variable warnings
> 
> On Wed, Sep 09, 2015 at 05:16:22PM +0800, Yuantian.Tang@freescale.com
> wrote:
> > From: Tang Yuantian <Yuantian.Tang@freescale.com>
> >
> > kbuild test robot reports the warnings:
> > drivers/ata/ahci_qoriq.c: In function 'ahci_qoriq_hardreset':
> > >> include/asm-generic/io.h:163:2: warning: 'px_is' may be used
> > >> uninitialized in this function [-Wuninitialized]
> > drivers/ata/ahci_qoriq.c:70:14: note: 'px_is' was declared here
> > >> include/asm-generic/io.h:163:2: warning: 'px_cmd' may be used
> > >> uninitialized in this function [-Wuninitialized]
> > drivers/ata/ahci_qoriq.c:70:6: note: 'px_cmd' was declared here
> >
> > This patch fixed it by assigning 0 to px_is and px_cmd variables.
> > This patch also remove line 'struct ccsr_ahci *reg_base' which is not
> > referred by any other codes and thus a dead one.
> 
> Hmm... I think the problem here is that the complier can't know whether
> qoriq_priv->type would change across intervening function calls.  Maybe a
> better solution is caching the type in a local variable so that the compiler can
> tell that those two tests will always move together?  It generally isn't a good
> idea to clear variables unnecessarily as that can hide actual bugs that compiler
> can detect.
> 
I am not sure if the warning can be removed this way.
But I will send the patch as your suggestion. 
Unfortunately, I can't produce this warning no matter if I add -Wuninitialized.
So please let me know if the new patch is working.

Regards,
Yuantian

> Thanks.
> 
> --
> tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
tang yuantian Sept. 11, 2015, 5:27 a.m. UTC | #4
Hi Tejun,

Could you please take the version 1 patch?
The version 2 patch can't address these warnings, and the version 1 can definitely remove them.
In this case, that would cause any hidden bugs, so no worries.

Regards,
Yuantian

> -----Original Message-----
> From: Tejun Heo [mailto:htejun@gmail.com] On Behalf Of Tejun Heo
> Sent: Wednesday, September 09, 2015 10:02 PM
> To: Tang Yuantian-B29983 <Yuantian.Tang@freescale.com>
> Cc: hdegoede@redhat.com; linux-ide@vger.kernel.org; linux-
> kernel@vger.kernel.org; devicetree@vger.kernel.org
> Subject: Re: [PATCH] ahci: qoriq: fixed using uninitialized variable warnings
> 
> On Wed, Sep 09, 2015 at 05:16:22PM +0800, Yuantian.Tang@freescale.com
> wrote:
> > From: Tang Yuantian <Yuantian.Tang@freescale.com>
> >
> > kbuild test robot reports the warnings:
> > drivers/ata/ahci_qoriq.c: In function 'ahci_qoriq_hardreset':
> > >> include/asm-generic/io.h:163:2: warning: 'px_is' may be used
> > >> uninitialized in this function [-Wuninitialized]
> > drivers/ata/ahci_qoriq.c:70:14: note: 'px_is' was declared here
> > >> include/asm-generic/io.h:163:2: warning: 'px_cmd' may be used
> > >> uninitialized in this function [-Wuninitialized]
> > drivers/ata/ahci_qoriq.c:70:6: note: 'px_cmd' was declared here
> >
> > This patch fixed it by assigning 0 to px_is and px_cmd variables.
> > This patch also remove line 'struct ccsr_ahci *reg_base' which is not
> > referred by any other codes and thus a dead one.
> 
> Hmm... I think the problem here is that the complier can't know whether
> qoriq_priv->type would change across intervening function calls.  Maybe a
> better solution is caching the type in a local variable so that the compiler can
> tell that those two tests will always move together?  It generally isn't a good
> idea to clear variables unnecessarily as that can hide actual bugs that compiler
> can detect.
> 
> Thanks.
> 
> --
> tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Tejun Heo Sept. 11, 2015, 1:54 p.m. UTC | #5
Hello, Yuantian.

On Fri, Sep 11, 2015 at 05:27:25AM +0000, Yuantian Tang wrote:
> Hi Tejun,
> 
> Could you please take the version 1 patch?
> The version 2 patch can't address these warnings, and the version 1 can definitely remove them.
> In this case, that would cause any hidden bugs, so no worries.

Ugh... I really hate changes which are made to just work around
compiler silliness.  If this is something which goes away with newer
gcc, Fengguang can just make it as a known false positive.  Yuantian,
which compiler are you using?

Thanks.
tang yuantian Sept. 14, 2015, 3:02 a.m. UTC | #6
Hello Tejun,

The toolchain I used is:
gcc version 4.8.3 20140401 (prerelease) (Linaro GCC 4.8-2014.04)

I have not found this warning using this tool chain with -Wuninitialized flag.

Regards,
Yuantian 

> -----Original Message-----
> From: Tejun Heo [mailto:htejun@gmail.com] On Behalf Of Tejun Heo
> Sent: Friday, September 11, 2015 9:55 PM
> To: Tang Yuantian-B29983 <Yuantian.Tang@freescale.com>
> Cc: hdegoede@redhat.com; linux-ide@vger.kernel.org; linux-
> kernel@vger.kernel.org; devicetree@vger.kernel.org; Fengguang Wu
> <fengguang.wu@intel.com>
> Subject: Re: [PATCH] ahci: qoriq: fixed using uninitialized variable warnings
> 
> Hello, Yuantian.
> 
> On Fri, Sep 11, 2015 at 05:27:25AM +0000, Yuantian Tang wrote:
> > Hi Tejun,
> >
> > Could you please take the version 1 patch?
> > The version 2 patch can't address these warnings, and the version 1 can
> definitely remove them.
> > In this case, that would cause any hidden bugs, so no worries.
> 
> Ugh... I really hate changes which are made to just work around compiler
> silliness.  If this is something which goes away with newer gcc, Fengguang can
> just make it as a known false positive.  Yuantian, which compiler are you
> using?
> 
> Thanks.
> 
> --
> tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
kbuild test robot Sept. 14, 2015, 4:04 a.m. UTC | #7
Yuantian,

It's cross compiling on ARCH=openrisc.

Thanks,
Fengguang

On Mon, Sep 14, 2015 at 03:02:27AM +0000, Yuantian Tang wrote:
> Hello Tejun,
> 
> The toolchain I used is:
> gcc version 4.8.3 20140401 (prerelease) (Linaro GCC 4.8-2014.04)
> 
> I have not found this warning using this tool chain with -Wuninitialized flag.
> 
> Regards,
> Yuantian 
> 
> > -----Original Message-----
> > From: Tejun Heo [mailto:htejun@gmail.com] On Behalf Of Tejun Heo
> > Sent: Friday, September 11, 2015 9:55 PM
> > To: Tang Yuantian-B29983 <Yuantian.Tang@freescale.com>
> > Cc: hdegoede@redhat.com; linux-ide@vger.kernel.org; linux-
> > kernel@vger.kernel.org; devicetree@vger.kernel.org; Fengguang Wu
> > <fengguang.wu@intel.com>
> > Subject: Re: [PATCH] ahci: qoriq: fixed using uninitialized variable warnings
> > 
> > Hello, Yuantian.
> > 
> > On Fri, Sep 11, 2015 at 05:27:25AM +0000, Yuantian Tang wrote:
> > > Hi Tejun,
> > >
> > > Could you please take the version 1 patch?
> > > The version 2 patch can't address these warnings, and the version 1 can
> > definitely remove them.
> > > In this case, that would cause any hidden bugs, so no worries.
> > 
> > Ugh... I really hate changes which are made to just work around compiler
> > silliness.  If this is something which goes away with newer gcc, Fengguang can
> > just make it as a known false positive.  Yuantian, which compiler are you
> > using?
> > 
> > Thanks.
> > 
> > --
> > tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
tang yuantian Sept. 14, 2015, 6:51 a.m. UTC | #8
The ARCH should have been ARM for this driver.
Do you think this warning would go away if adding a dependency on ARM?

Regards,
Yuantian

> -----Original Message-----
> From: Fengguang Wu [mailto:fengguang.wu@intel.com]
> Sent: Monday, September 14, 2015 12:05 PM
> To: Tang Yuantian-B29983 <Yuantian.Tang@freescale.com>
> Cc: Tejun Heo <tj@kernel.org>; hdegoede@redhat.com; linux-
> ide@vger.kernel.org; linux-kernel@vger.kernel.org;
> devicetree@vger.kernel.org
> Subject: Re: [PATCH] ahci: qoriq: fixed using uninitialized variable warnings
> 
> Yuantian,
> 
> It's cross compiling on ARCH=openrisc.
> 
> Thanks,
> Fengguang
> 
> On Mon, Sep 14, 2015 at 03:02:27AM +0000, Yuantian Tang wrote:
> > Hello Tejun,
> >
> > The toolchain I used is:
> > gcc version 4.8.3 20140401 (prerelease) (Linaro GCC 4.8-2014.04)
> >
> > I have not found this warning using this tool chain with -Wuninitialized flag.
> >
> > Regards,
> > Yuantian
> >
> > > -----Original Message-----
> > > From: Tejun Heo [mailto:htejun@gmail.com] On Behalf Of Tejun Heo
> > > Sent: Friday, September 11, 2015 9:55 PM
> > > To: Tang Yuantian-B29983 <Yuantian.Tang@freescale.com>
> > > Cc: hdegoede@redhat.com; linux-ide@vger.kernel.org; linux-
> > > kernel@vger.kernel.org; devicetree@vger.kernel.org; Fengguang Wu
> > > <fengguang.wu@intel.com>
> > > Subject: Re: [PATCH] ahci: qoriq: fixed using uninitialized variable
> > > warnings
> > >
> > > Hello, Yuantian.
> > >
> > > On Fri, Sep 11, 2015 at 05:27:25AM +0000, Yuantian Tang wrote:
> > > > Hi Tejun,
> > > >
> > > > Could you please take the version 1 patch?
> > > > The version 2 patch can't address these warnings, and the version
> > > > 1 can
> > > definitely remove them.
> > > > In this case, that would cause any hidden bugs, so no worries.
> > >
> > > Ugh... I really hate changes which are made to just work around
> > > compiler silliness.  If this is something which goes away with newer
> > > gcc, Fengguang can just make it as a known false positive.
> > > Yuantian, which compiler are you using?
> > >
> > > Thanks.
> > >
> > > --
> > > tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
kbuild test robot Sept. 14, 2015, 6:54 a.m. UTC | #9
On Mon, Sep 14, 2015 at 06:51:36AM +0000, Yuantian Tang wrote:
> The ARCH should have been ARM for this driver.
> Do you think this warning would go away if adding a dependency on ARM?

Yes, that may work.

Thanks,
Fengguang

> > -----Original Message-----
> > From: Fengguang Wu [mailto:fengguang.wu@intel.com]
> > Sent: Monday, September 14, 2015 12:05 PM
> > To: Tang Yuantian-B29983 <Yuantian.Tang@freescale.com>
> > Cc: Tejun Heo <tj@kernel.org>; hdegoede@redhat.com; linux-
> > ide@vger.kernel.org; linux-kernel@vger.kernel.org;
> > devicetree@vger.kernel.org
> > Subject: Re: [PATCH] ahci: qoriq: fixed using uninitialized variable warnings
> > 
> > Yuantian,
> > 
> > It's cross compiling on ARCH=openrisc.
> > 
> > Thanks,
> > Fengguang
> > 
> > On Mon, Sep 14, 2015 at 03:02:27AM +0000, Yuantian Tang wrote:
> > > Hello Tejun,
> > >
> > > The toolchain I used is:
> > > gcc version 4.8.3 20140401 (prerelease) (Linaro GCC 4.8-2014.04)
> > >
> > > I have not found this warning using this tool chain with -Wuninitialized flag.
> > >
> > > Regards,
> > > Yuantian
> > >
> > > > -----Original Message-----
> > > > From: Tejun Heo [mailto:htejun@gmail.com] On Behalf Of Tejun Heo
> > > > Sent: Friday, September 11, 2015 9:55 PM
> > > > To: Tang Yuantian-B29983 <Yuantian.Tang@freescale.com>
> > > > Cc: hdegoede@redhat.com; linux-ide@vger.kernel.org; linux-
> > > > kernel@vger.kernel.org; devicetree@vger.kernel.org; Fengguang Wu
> > > > <fengguang.wu@intel.com>
> > > > Subject: Re: [PATCH] ahci: qoriq: fixed using uninitialized variable
> > > > warnings
> > > >
> > > > Hello, Yuantian.
> > > >
> > > > On Fri, Sep 11, 2015 at 05:27:25AM +0000, Yuantian Tang wrote:
> > > > > Hi Tejun,
> > > > >
> > > > > Could you please take the version 1 patch?
> > > > > The version 2 patch can't address these warnings, and the version
> > > > > 1 can
> > > > definitely remove them.
> > > > > In this case, that would cause any hidden bugs, so no worries.
> > > >
> > > > Ugh... I really hate changes which are made to just work around
> > > > compiler silliness.  If this is something which goes away with newer
> > > > gcc, Fengguang can just make it as a known false positive.
> > > > Yuantian, which compiler are you using?
> > > >
> > > > Thanks.
> > > >
> > > > --
> > > > tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-ide" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/ata/ahci_qoriq.c b/drivers/ata/ahci_qoriq.c
index e5e4988..f790852 100644
--- a/drivers/ata/ahci_qoriq.c
+++ b/drivers/ata/ahci_qoriq.c
@@ -49,7 +49,6 @@  enum ahci_qoriq_type {
 };
 
 struct ahci_qoriq_priv {
-	struct ccsr_ahci *reg_base;
 	enum ahci_qoriq_type type;
 	void __iomem *ecc_addr;
 };
@@ -67,7 +66,7 @@  static int ahci_qoriq_hardreset(struct ata_link *link, unsigned int *class,
 {
 	const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
 	void __iomem *port_mmio = ahci_port_base(link->ap);
-	u32 px_cmd, px_is, px_val;
+	u32 px_cmd = 0, px_is = 0, px_val;
 	struct ata_port *ap = link->ap;
 	struct ahci_port_priv *pp = ap->private_data;
 	struct ahci_host_priv *hpriv = ap->host->private_data;