Skip to contentSkip to conversation

net: ethernet: ti: cpsw: fix NULL pointer dereference in switch mode

PATCH Applied Grygorii Strashko 3 participants 3 messages Jan 31, 2017 – Feb 1, 2017

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

PATCH 1/1 net: ethernet: ti: cpsw: fix NULL pointer dereference in switch mode

In switch mode on struct cpsw_slave->ndev field will be initialized with proper value only for the one cpsw slave port, as result cpsw_get_usage_count() will generate "Unable to handle kernel NULL pointer dereference" exception when first ethernet interface is opening cpsw_ndo_open(). This issue causes boot regression on AM335x EVM and reproducible on am57xx-evm (switch mode).
Fix it by adding additional check for !cpsw->slaves[i].ndev in cpsw_get_usage_count().

Cc Ivan Khoronzhuk <[email protected]>
Fixes 03fd01ad0eea ("net: ethernet: ti: cpsw: don't duplicate ndev_running")
---
 drivers/net/ethernet/ti/cpsw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ti/cpsw.c +1 -1
index 67b7323..35a95dc 100644
@@ -677,7 +677,7 @@ static int cpsw_get_usage_count(struct cpsw_common *cpsw)
 	u32 usage_count = 0;
 
 	for (i = 0; i < cpsw->data.slaves; i++)
-		if (netif_running(cpsw->slaves[i].ndev))
+		if (cpsw->slaves[i].ndev && netif_running(cpsw->slaves[i].ndev))
 			usage_count++;
 
 	return usage_count;
Signature · 1 line
2.10.1.dirty
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Grygorii Strashko

In switch mode on struct cpsw_slave->ndev field will be initialized with proper value only for the one cpsw slave port, as result cpsw_get_usage_count() will generate "Unable to handle kernel NULL pointer dereference" exception when first ethernet interface is opening cpsw_ndo_open(). This issue causes boot regression on AM335x EVM and reproducible on am57xx-evm (switch mode).
Fix it by adding additional check for !cpsw->slaves[i].ndev in cpsw_get_usage_count().

Quoted 4 lines
Cc Ivan Khoronzhuk <[email protected]>
Fixes 03fd01ad0eea ("net: ethernet: ti: cpsw: don't duplicate ndev_running")

---

Yes, unfortunately forgot to add it. Thanks.

Quoted 19 lines
 drivers/net/ethernet/ti/cpsw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ti/cpsw.c +1 -1
index 67b7323..35a95dc 100644
@@ -677,7 +677,7 @@ static int cpsw_get_usage_count(struct cpsw_common *cpsw)
 	u32 usage_count = 0;
 
 	for (i = 0; i < cpsw->data.slaves; i++)
-		if (netif_running(cpsw->slaves[i].ndev))
+		if (cpsw->slaves[i].ndev && netif_running(cpsw->slaves[i].ndev))
 			usage_count++;
 
 	return usage_count;
Signature · 1 line
2.10.1.dirty
maintainer Applied
#2 lore raw
In reply to Grygorii Strashko

From: Grygorii Strashko <[email protected]>
Date: Tue, 31 Jan 2017 14:04:04 -0600

Quoted 11 lines

In switch mode on struct cpsw_slave->ndev field will be initialized with proper value only for the one cpsw slave port, as result cpsw_get_usage_count() will generate "Unable to handle kernel NULL pointer dereference" exception when first ethernet interface is opening cpsw_ndo_open(). This issue causes boot regression on AM335x EVM and reproducible on am57xx-evm (switch mode).
Fix it by adding additional check for !cpsw->slaves[i].ndev in cpsw_get_usage_count().

Cc Ivan Khoronzhuk <[email protected]>
Fixes 03fd01ad0eea ("net: ethernet: ti: cpsw: don't duplicate ndev_running")

Please capitalize "Fixes: " in the future.

Quoted 1 line

Applied, thanks.