Skip to contentSkip to conversation

net: dsa: OF parsing fixes

PATCH In review Florian Fainelli 2 participants 4 messages Jul 12, 2015

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

cover net: dsa: OF parsing fixes

Hi David,

This patch series fixes two small parsing issues, the first one was reported by Dan, the second came after looking more closely at the code.

Thanks!

Florian Fainelli (2):
net: dsa: Test array index before use
net: dsa: Fix off-by-one in switch address parsing

 net/dsa/dsa.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/2 net: dsa: Test array index before use

port_index is used an index into an array, and this information comes from Device Tree, make sure that port_index is not equal to the array size before using it. Move the check against port_index earlier in the loop.

Fixes 5e95329b701c: ("dsa: add device tree bindings to register DSA switches")
---
 net/dsa/dsa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/dsa/dsa.c +2 -2
index 392e29a0227d..52beeb8829dc 100644
@@ -642,6 +642,8 @@ static int dsa_of_probe(struct device *dev)
 				continue;
 
 			port_index = be32_to_cpup(port_reg);
+			if (port_index >= DSA_MAX_PORTS)
+				break;
 
 			port_name = of_get_property(port, "label", NULL);
 			if (!port_name)
@@ -666,8 +668,6 @@ static int dsa_of_probe(struct device *dev)
 					goto out_free_chip;
 			}
 
-			if (port_index == DSA_MAX_PORTS)
-				break;
 		}
 	}
 
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/2 net: dsa: Fix off-by-one in switch address parsing

In reply to Florian Fainelli

cd->sw_addr is used as a MDIO bus address, which cannot exceed PHY_MAX_ADDR (32), our check was off-by-one.

Fixes 5e95329b701c ("dsa: add device tree bindings to register DSA switches")
---
 net/dsa/dsa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/dsa/dsa.c +1 -1
index 52beeb8829dc..b445d492c115 100644
@@ -630,7 +630,7 @@ static int dsa_of_probe(struct device *dev)
 			continue;
 
 		cd->sw_addr = be32_to_cpup(sw_addr);
-		if (cd->sw_addr > PHY_MAX_ADDR)
+		if (cd->sw_addr >= PHY_MAX_ADDR)
 			continue;
 
 		if (!of_property_read_u32(child, "eeprom-length", &eeprom_len))
Signature · 1 line
2.1.4
maintainer
#3 lore raw
In reply to Florian Fainelli

From: Florian Fainelli <[email protected]>
Date: Sat, 11 Jul 2015 18:02:09 -0700

Quoted 3 lines

This patch series fixes two small parsing issues, the first one was reported by Dan, the second came after looking more closely at the code.

Series applied, thanks Florian.