Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] brcmfmac: check ndev pointer
@ 2020-08-02 16:18 trix
  2020-08-18 12:50 ` Kalle Valo
  0 siblings, 1 reply; 2+ messages in thread
From: trix @ 2020-08-02 16:18 UTC (permalink / raw)
  To: arend.vanspriel, franky.lin, hante.meuleman, chi-hsien.lin,
	wright.feng, kvalo, davem, kuba, rafal, tklauser
  Cc: linux-wireless, brcm80211-dev-list.pdl, brcm80211-dev-list,
	netdev, linux-kernel, Tom Rix

From: Tom Rix <trix@redhat.com>

Clang static analysis reports this error

brcmfmac/core.c:490:4: warning: Dereference of null pointer
        (*ifp)->ndev->stats.rx_errors++;
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In this block of code

	if (ret || !(*ifp) || !(*ifp)->ndev) {
		if (ret != -ENODATA && *ifp)
			(*ifp)->ndev->stats.rx_errors++;
		brcmu_pkt_buf_free_skb(skb);
		return -ENODATA;
	}

(*ifp)->ndev being NULL is caught as an error
But then it is used to report the error.

So add a check before using it.

Fixes: 91b632803ee4 ("brcmfmac: Use net_device_stats from struct net_device")

Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
index f89010a81ffb..aa9ced3c86fb 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
@@ -486,7 +486,7 @@ static int brcmf_rx_hdrpull(struct brcmf_pub *drvr, struct sk_buff *skb,
 	ret = brcmf_proto_hdrpull(drvr, true, skb, ifp);
 
 	if (ret || !(*ifp) || !(*ifp)->ndev) {
-		if (ret != -ENODATA && *ifp)
+		if (ret != -ENODATA && *ifp && (*ifp)->ndev)
 			(*ifp)->ndev->stats.rx_errors++;
 		brcmu_pkt_buf_free_skb(skb);
 		return -ENODATA;
-- 
2.18.1


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

* Re: [PATCH] brcmfmac: check ndev pointer
  2020-08-02 16:18 [PATCH] brcmfmac: check ndev pointer trix
@ 2020-08-18 12:50 ` Kalle Valo
  0 siblings, 0 replies; 2+ messages in thread
From: Kalle Valo @ 2020-08-18 12:50 UTC (permalink / raw)
  To: trix
  Cc: arend.vanspriel, franky.lin, hante.meuleman, chi-hsien.lin,
	wright.feng, davem, kuba, rafal, tklauser, linux-wireless,
	brcm80211-dev-list.pdl, brcm80211-dev-list, netdev, linux-kernel,
	Tom Rix

trix@redhat.com wrote:

> From: Tom Rix <trix@redhat.com>
> 
> Clang static analysis reports this error
> 
> brcmfmac/core.c:490:4: warning: Dereference of null pointer
>         (*ifp)->ndev->stats.rx_errors++;
>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> In this block of code
> 
> 	if (ret || !(*ifp) || !(*ifp)->ndev) {
> 		if (ret != -ENODATA && *ifp)
> 			(*ifp)->ndev->stats.rx_errors++;
> 		brcmu_pkt_buf_free_skb(skb);
> 		return -ENODATA;
> 	}
> 
> (*ifp)->ndev being NULL is caught as an error
> But then it is used to report the error.
> 
> So add a check before using it.
> 
> Fixes: 91b632803ee4 ("brcmfmac: Use net_device_stats from struct net_device")
> Signed-off-by: Tom Rix <trix@redhat.com>

Patch applied to wireless-drivers-next.git, thanks.

9c9f015bc9f8 brcmfmac: check ndev pointer

-- 
https://patchwork.kernel.org/patch/11696567/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


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

end of thread, other threads:[~2020-08-18 12:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-02 16:18 [PATCH] brcmfmac: check ndev pointer trix
2020-08-18 12:50 ` Kalle Valo

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).