Skip to contentSkip to conversation

mpc832x_rdb.c: prevent using uninitialized variable

PATCH In review Anton Vorontsov 2 participants 3 messages Jul 26, 2007 – Jul 27, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mpc832x_rdb.c: prevent using uninitialized variable

If CONFIG_PCI undefined, np will be used uninitialized, thereby find_node_by_name(np, "par_io") will fail.

---
 arch/powerpc/platforms/83xx/mpc832x_rdb.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/platforms/83xx/mpc832x_rdb.c +2 -2
index c5463c7..b16dce2 100644
@@ -79,14 +79,14 @@ device_initcall(mpc83xx_spi_devices_init);
 static void __init mpc832x_rdb_setup_arch(void)
 {
 #if defined(CONFIG_PCI) || defined(CONFIG_QUICC_ENGINE)
-	struct device_node *np;
+	struct device_node *np = NULL;
 #endif
 
 	if (ppc_md.progress)
 		ppc_md.progress("mpc832x_rdb_setup_arch()", 0);
 
 #ifdef CONFIG_PCI
-	for (np = NULL; (np = of_find_node_by_type(np, "pci")) != NULL;)
+	for (; (np = of_find_node_by_type(np, "pci")) != NULL;)
 		mpc83xx_add_bridge(np);
 
 	ppc_md.pci_exclude_device = mpc83xx_exclude_device;
Signature · 1 line
1.5.0.6
#1 lore raw
Quoted 2 lines · Anton Vorontsov

If CONFIG_PCI undefined, np will be used uninitialized, thereby find_node_by_name(np, "par_io") will fail.

This is the wrong fix -- you should be passing NULL to the par_io call rather than np. Otherwise, if the par_io is earlier in the tree than the pci, you won't find it.

-Scott

#2 lore raw
Quoted 7 lines · Scott Wood
Quoted 2 lines · Anton Vorontsov

If CONFIG_PCI undefined, np will be used uninitialized, thereby find_node_by_name(np, "par_io") will fail.

This is the wrong fix -- you should be passing NULL to the par_io call rather than np. Otherwise, if the par_io is earlier in the tree than the pci, you won't find it.

Oops. Right you are, thanks!

I hope this is proper fix.

- - - -
From: Anton Vorontsov <[email protected]>
Subject: [POWERPC] mpc832x_rdb.c: prevent using uninitialized variable

If CONFIG_PCI undefined, np will be used uninitialized, thereby find_node_by_name(np, "par_io") will fail.

of_find_node_by_name(np, "par_io") isn't used inside loop, thus we can safely pass NULL instead of np.

---
 arch/powerpc/platforms/83xx/mpc832x_rdb.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/platforms/83xx/mpc832x_rdb.c +1 -1
index b2b28a4..93ba957 100644
@@ -56,7 +56,7 @@ static void __init mpc832x_rdb_setup_arch(void)
 #ifdef CONFIG_QUICC_ENGINE
 	qe_reset();
 
-	if ((np = of_find_node_by_name(np, "par_io")) != NULL) {
+	if ((np = of_find_node_by_name(NULL, "par_io")) != NULL) {
 		par_io_init(np);
 		of_node_put(np);
 
Signature · 1 line
1.5.0.6