From: Arend van Spriel Date: Wed, 17 Apr 2013 19:25:50 +0000 (+0200) Subject: brcmfmac: check memory allocation in brcmf_add_if() X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=991c209393bc30ccb36e212167bf3ecb5f33ff07;p=linux-beck.git brcmfmac: check memory allocation in brcmf_add_if() For P2P_DEVICE interface the struct brcmf_if instance is allocated using kzalloc() which can fail. Add pointer check and return -ENOMEM if it failed. Fixes the following smatch error: "drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c:770 brcmf_add_if() error: potential null dereference 'ifp'. (kzalloc returns null)" Reported-by: Dan Carpenter Reported-by: Fengguang Wu Reviewed-by: Hante Meuleman Reviewed-by: Piotr Haber Signed-off-by: Arend van Spriel Signed-off-by: John W. Linville --- diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c index 763a84eba216..269fde2a8168 100644 --- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c +++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c @@ -754,6 +754,8 @@ struct brcmf_if *brcmf_add_if(struct brcmf_pub *drvr, s32 bssidx, s32 ifidx, /* this is P2P_DEVICE interface */ brcmf_dbg(INFO, "allocate non-netdev interface\n"); ifp = kzalloc(sizeof(*ifp), GFP_KERNEL); + if (!ifp) + return ERR_PTR(-ENOMEM); } else { brcmf_dbg(INFO, "allocate netdev interface\n"); /* Allocate netdev, including space for private structure */