Commit f6961862 authored by Grygorii Strashko's avatar Grygorii Strashko Committed by David S. Miller

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 <ivan.khoronzhuk@linaro.org>
Fixes: 03fd01ad ("net: ethernet: ti: cpsw: don't duplicate ndev_running")
Signed-off-by: default avatarGrygorii Strashko <grygorii.strashko@ti.com>
Reviewed-by: default avatarIvan Khoronzhuk <ivan.khoronzhuk@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b2504a5d
...@@ -677,7 +677,7 @@ static int cpsw_get_usage_count(struct cpsw_common *cpsw) ...@@ -677,7 +677,7 @@ static int cpsw_get_usage_count(struct cpsw_common *cpsw)
u32 usage_count = 0; u32 usage_count = 0;
for (i = 0; i < cpsw->data.slaves; i++) 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++; usage_count++;
return usage_count; return usage_count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment