netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: ti: cpsw: fix  NULL pointer dereference in switch mode
@ 2017-01-31 20:04 Grygorii Strashko
  2017-02-01 16:30 ` Ivan Khoronzhuk
  2017-02-01 17:06 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Grygorii Strashko @ 2017-01-31 20:04 UTC (permalink / raw)
  To: David S. Miller, netdev, Ivan Khoronzhuk
  Cc: Sekhar Nori, linux-kernel, linux-omap, 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().

Cc: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>
fixes: 03fd01ad0eea ("net: ethernet: ti: cpsw: don't duplicate ndev_running")
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
---
 drivers/net/ethernet/ti/cpsw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index 67b7323..35a95dc 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -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;
-- 
2.10.1.dirty

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: ethernet: ti: cpsw: fix  NULL pointer dereference in switch mode
  2017-01-31 20:04 [PATCH] net: ethernet: ti: cpsw: fix NULL pointer dereference in switch mode Grygorii Strashko
@ 2017-02-01 16:30 ` Ivan Khoronzhuk
  2017-02-01 17:06 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Ivan Khoronzhuk @ 2017-02-01 16:30 UTC (permalink / raw)
  To: Grygorii Strashko
  Cc: David S. Miller, netdev, Sekhar Nori, linux-kernel, linux-omap

On Tue, Jan 31, 2017 at 02:04:04PM -0600, Grygorii Strashko wrote:
> 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: 03fd01ad0eea ("net: ethernet: ti: cpsw: don't duplicate ndev_running")
> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
> ---

Yes, unfortunately forgot to add it. Thanks.
Reviewed-by: Ivan Khoronzhuk <ivan.khoronzhuk@linaro.org>


>  drivers/net/ethernet/ti/cpsw.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
> index 67b7323..35a95dc 100644
> --- a/drivers/net/ethernet/ti/cpsw.c
> +++ b/drivers/net/ethernet/ti/cpsw.c
> @@ -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;
> -- 
> 2.10.1.dirty
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: ethernet: ti: cpsw: fix NULL pointer dereference in switch mode
  2017-01-31 20:04 [PATCH] net: ethernet: ti: cpsw: fix NULL pointer dereference in switch mode Grygorii Strashko
  2017-02-01 16:30 ` Ivan Khoronzhuk
@ 2017-02-01 17:06 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-02-01 17:06 UTC (permalink / raw)
  To: grygorii.strashko
  Cc: netdev, ivan.khoronzhuk, nsekhar, linux-kernel, linux-omap

From: Grygorii Strashko <grygorii.strashko@ti.com>
Date: Tue, 31 Jan 2017 14:04:04 -0600

> 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: 03fd01ad0eea ("net: ethernet: ti: cpsw: don't duplicate ndev_running")

Please capitalize "Fixes: " in the future.

> Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-01 17:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-31 20:04 [PATCH] net: ethernet: ti: cpsw: fix NULL pointer dereference in switch mode Grygorii Strashko
2017-02-01 16:30 ` Ivan Khoronzhuk
2017-02-01 17:06 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).