brcmfmac: check ndev pointer
authorTom Rix <trix@redhat.com>
Sun, 2 Aug 2020 16:18:04 +0000 (09:18 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 08:07:03 +0000 (09:07 +0100)
[ Upstream commit 9c9f015bc9f8839831c7ba0a6d731a3853c464e2 ]

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>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20200802161804.6126-1-trix@redhat.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c

index bfc0e37b7f344eb95530383c8560c6ca9e7dea14..590bef2defb94eb0ad68440a341b0a0495019c53 100644 (file)
@@ -318,7 +318,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;