net: wireless: bcmdhd: fix Coverity defects
Michael Hsu [Mon, 21 Dec 2015 01:16:57 +0000 (17:16 -0800)]
Fix potential NULL pointer dereferences reported by Coverity.

Coverity id: 12628, 12629, 19020

Bug 1416640

Change-Id: I57cd859e2bc50f7ca46b6789b27ba89a52148509
Signed-off-by: Michael Hsu <mhsu@nvidia.com>
Reviewed-on: http://git-master/r/925281
GVS: Gerrit_Virtual_Submit
Reviewed-by: Bharat Nihalani <bnihalani@nvidia.com>
Reviewed-by: Ashutosh Jha <ajha@nvidia.com>

drivers/net/wireless/bcmdhd/dhd_linux.c

index 2bad9d7..b5902cf 100644 (file)
@@ -4604,6 +4604,8 @@ dhd_event_ifadd(dhd_info_t *dhdinfo, wl_event_data_if_t *ifevent, char *name, ui
        if (ifevent->ifidx > 0) {
                dhd_if_event_t *if_event = MALLOC(dhdinfo->pub.osh, sizeof(dhd_if_event_t));
 
+               if (if_event == NULL)
+                       return BCME_NOMEM;
                memcpy(&if_event->event, ifevent, sizeof(if_event->event));
                memcpy(if_event->mac, mac, ETHER_ADDR_LEN);
                strncpy(if_event->name, name, IFNAMSIZ);
@@ -4637,6 +4639,8 @@ dhd_event_ifdel(dhd_info_t *dhdinfo, wl_event_data_if_t *ifevent, char *name, ui
         * anything else
         */
        if_event = MALLOC(dhdinfo->pub.osh, sizeof(dhd_if_event_t));
+       if (if_event == NULL)
+               return BCME_NOMEM;
        memcpy(&if_event->event, ifevent, sizeof(if_event->event));
        memcpy(if_event->mac, mac, ETHER_ADDR_LEN);
        strncpy(if_event->name, name, IFNAMSIZ);
@@ -9711,6 +9715,8 @@ void dhd_schedule_memdump(dhd_pub_t *dhdp, uint8 *buf, uint32 size)
 {
        dhd_dump_t *dump = NULL;
        dump = MALLOC(dhdp->osh, sizeof(dhd_dump_t));
+       if (dump == NULL)
+               return;
        dump->buf = buf;
        dump->bufsize = size;
        dhd_deferred_schedule_work(dhdp->info->dhd_deferred_wq, (void *)dump,