Skip to contentSkip to conversation

mcf: Fix cppcheck errors about uninitialized variables

PATCH New Alison Wang 4 participants 4 messages Nov 14, 2014 – Nov 18, 2014 m68k architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mcf: Fix cppcheck errors about uninitialized variables

This patch will initialize the variables to fix the cppcheck errors as follows.

[arch/m68k/cpu/mcf5227x/speed.c:89]: (error) Uninitialized variable: bootmode [arch/m68k/cpu/mcf532x/speed.c:248]: (error) Uninitialized variable: fout [arch/m68k/cpu/mcf5445x/speed.c:194]: (error) Uninitialized variable: bootmode

---
 arch/m68k/cpu/mcf5227x/speed.c | 2 +-
 arch/m68k/cpu/mcf532x/speed.c  | 3 ++-
 arch/m68k/cpu/mcf5445x/speed.c | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
arch/m68k/cpu/mcf5227x/speed.c +1 -1
index 44de4a6..e991cd1 100644
@@ -74,7 +74,7 @@ int get_clocks(void)
 	ccm_t *ccm = (ccm_t *)MMAP_CCM;
 	pll_t *pll = (pll_t *)MMAP_PLL;
 	int vco, temp, pcrvalue, pfdr;
-	u8 bootmode;
+	u8 bootmode = 0;
 
 	pcrvalue = in_be32(&pll->pcr) & 0xFF0F0FFF;
 	pfdr = pcrvalue >> 24;
arch/m68k/cpu/mcf532x/speed.c +2 -1
index a440bbb..0495b16 100644
@@ -143,7 +143,8 @@ int clock_pll(int fsys, int flags)
 #endif
 	sdram_t *sdram = (sdram_t *)(MMAP_SDRAM);
 	pll_t *pll = (pll_t *)(MMAP_PLL);
-	int fref, temp, fout, mfd;
+	int fref, temp, mfd;
+	int fout = 0;
 	u32 i;
 
 	fref = FREF;
arch/m68k/cpu/mcf5445x/speed.c +1 -1
index 4e363a4..a166dcc 100644
@@ -141,7 +141,7 @@ void setup_5445x_clocks(void)
 #ifdef CONFIG_M54455EVB
 	u8 *cpld = (u8 *)(CONFIG_SYS_CS2_BASE + 3);
 #endif
-	u8 bootmode;
+	u8 bootmode = 0;
 
 	/* To determine PCI is present or not */
 	if (((in_be16(&ccm->ccr) & CCM_CCR_360_FBCONFIG_MASK) == 0x00e0) ||
Signature · 1 line
2.1.0.27.g96db324
#1 lore raw

PATCH 1/1 mcf: Fix cppcheck errors about uninitialized variables

Hello Alison,

Quoted 19 lines · Alison Wang

This patch will initialize the variables to fix the cppcheck errors as follows.

[arch/m68k/cpu/mcf5227x/speed.c:89]: (error) Uninitialized variable: bootmode [arch/m68k/cpu/mcf532x/speed.c:248]: (error) Uninitialized variable: fout [arch/m68k/cpu/mcf5445x/speed.c:194]: (error) Uninitialized variable: bootmode

---
 arch/m68k/cpu/mcf5227x/speed.c | 2 +-
 arch/m68k/cpu/mcf532x/speed.c  | 3 ++-
 arch/m68k/cpu/mcf5445x/speed.c | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
arch/m68k/cpu/mcf5227x/speed.c +0 -0
index 44de4a6..e991cd1 100644

arch/m68k/cpu/mcf5227x/speed.c int get_clocks(void) · line 77

Quoted 5 lines
arch/m68k/cpu/mcf5227x/speed.c +1 -1
@@ -74,7 +74,7 @@ int get_clocks(void)
 	ccm_t *ccm = (ccm_t *)MMAP_CCM;
 	pll_t *pll = (pll_t *)MMAP_PLL;
 	int vco, temp, pcrvalue, pfdr;
-	u8 bootmode;
+	u8 bootmode = 0;

If you set bootmode to the default 0 value at declaration, then the code that follows in the source file can be simplified:

	u8 bootmode = 0;
---8<---
	pcrvalue = in_be32(&pll->pcr) & 0xFF0F0FFF;
	pfdr = pcrvalue >> 24;

	if (pfdr == 0x1E)
		bootmode = 0;	/* Normal Mode */

---8<---

The part between scissors is useless now, and in turn, pfdr becomes unneeded.

Quoted 7 lines
arch/m68k/cpu/mcf5227x/speed.c +0 -0
 	pcrvalue = in_be32(&pll->pcr) & 0xFF0F0FFF;
 	pfdr = pcrvalue >> 24;
arch/m68k/cpu/mcf532x/speed.c +0 -0
index a440bbb..0495b16 100644

arch/m68k/cpu/mcf532x/speed.c int clock_pll(int fsys, int flags) · line 148

Quoted 7 lines
arch/m68k/cpu/mcf532x/speed.c +2 -1
@@ -143,7 +143,8 @@ int clock_pll(int fsys, int flags)
 #endif
 	sdram_t *sdram = (sdram_t *)(MMAP_SDRAM);
 	pll_t *pll = (pll_t *)(MMAP_PLL);
-	int fref, temp, fout, mfd;
+	int fref, temp, mfd;
+	int fout = 0;
 	u32 i;

(haven't checked if similar reductions can be done)

arch/m68k/cpu/mcf5445x/speed.c void setup_5445x_clocks(void) · line 144

Quoted 11 lines
arch/m68k/cpu/mcf532x/speed.c +0 -0
 	fref = FREF;
arch/m68k/cpu/mcf5445x/speed.c +1 -1
index 4e363a4..a166dcc 100644
@@ -141,7 +141,7 @@ void setup_5445x_clocks(void)
 #ifdef CONFIG_M54455EVB
 	u8 *cpld = (u8 *)(CONFIG_SYS_CS2_BASE + 3);
 #endif
-	u8 bootmode;
+	u8 bootmode = 0;

(ditto)

Quoted 9 lines
arch/m68k/cpu/mcf5445x/speed.c +0 -0
 	/* To determine PCI is present or not */
 	if (((in_be16(&ccm->ccr) & CCM_CCR_360_FBCONFIG_MASK) == 0x00e0) ||
Signature · 6 lines
2.1.0.27.g96db324

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Amicalement,

Signature · 1 line
Albert.
#2 lore raw

PATCH 1/1 mcf: Fix cppcheck errors about uninitialized variables

Dear Albert,

Quoted 14 lines · In message <20141114134733.01c82023@lilith> you wrote:

Review

Quoted 3 lines
(quoted diff) +1 -1
-	u8 bootmode;
+	u8 bootmode = 0;

If you set bootmode to the default 0 value at declaration, then the code that follows in the source file can be simplified:

	u8 bootmode = 0;
---8<---
	pcrvalue = in_be32(&pll->pcr) & 0xFF0F0FFF;
	pfdr = pcrvalue >> 24;

	if (pfdr == 0x1E)
		bootmode = 0;	/* Normal Mode */
Quoted 3 lines

---8<---

The part between scissors is useless now, and in turn, pfdr becomes unneeded.

Exactly. This was my concern, too - otherwise I had provided auch a trivial fix. But I think here some deeper understanding of the intended logic is needed.

Best regards,

Wolfgang Denk

Signature · 4 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Brain: an apparatus with which we think we think.    - Ambrose Bierce
#3 lore raw

PATCH 1/1 mcf: Fix cppcheck errors about uninitialized variables

Quoted 19 lines · Wolfgang Denk

Dear Albert,

Quoted 16 lines · In message <20141114134733.01c82023@lilith> you wrote:

Review

Quoted 3 lines
(quoted diff) +1 -1
-	u8 bootmode;
+	u8 bootmode = 0;

If you set bootmode to the default 0 value at declaration, then the code that follows in the source file can be simplified:

	u8 bootmode = 0;
---8<---
	pcrvalue = in_be32(&pll->pcr) & 0xFF0F0FFF;
	pfdr = pcrvalue >> 24;

	if (pfdr == 0x1E)
		bootmode = 0;	/* Normal Mode */

---8<---

Quoted 5 lines
Quoted 1 line

The part between scissors is useless now, and in turn, pfdr becomes unneeded.

Exactly. This was my concern, too - otherwise I had provided auch a trivial fix. But I think here some deeper understanding of the intended logic is needed.

For clarity, yes, please do a v2 where you've re-organized the code based on what the cppcheck errors point out rather than just a simple silence of the warning, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20141118/0eaea90f/attachment.pgp>