wlan: Fix dereference before NULL check in netdev notifier
Static source code analysis uncovered an issue in
hdd_netdev_notifier_call() where it was dereferencing the pAdapter and
then subsequently checking it for NULL. Update to code to NULL-check
the pAdapter before it is dereferenced.
Change-Id: Id480c288646a019d2c39d8d895b9a2192cfb924d
diff --git a/CORE/HDD/src/wlan_hdd_main.c b/CORE/HDD/src/wlan_hdd_main.c
index 030d5c6..ef5a03f 100644
--- a/CORE/HDD/src/wlan_hdd_main.c
+++ b/CORE/HDD/src/wlan_hdd_main.c
@@ -190,30 +190,37 @@
{
struct net_device *dev = ndev;
hdd_adapter_t *pAdapter = WLAN_HDD_GET_PRIV_PTR(dev);
- hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX( pAdapter );
+ hdd_context_t *pHddCtx;
#ifdef WLAN_BTAMP_FEATURE
VOS_STATUS status;
hdd_context_t *pHddCtx;
#endif
//Make sure that this callback corresponds to our device.
- if((strncmp( dev->name, "wlan", 4 )) &&
- (strncmp( dev->name, "p2p", 3))
- )
+ if ((strncmp(dev->name, "wlan", 4)) &&
+ (strncmp(dev->name, "p2p", 3)))
return NOTIFY_DONE;
if (!dev->ieee80211_ptr)
- return NOTIFY_DONE;
+ return NOTIFY_DONE;
-
- if(NULL == pAdapter)
+ if (NULL == pAdapter)
{
hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Adapter Null Pointer", __func__);
VOS_ASSERT(0);
return NOTIFY_DONE;
}
- hddLog(VOS_TRACE_LEVEL_INFO,"%s: New Net Device State = %lu", __func__, state);
+ pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
+ if (NULL == pHddCtx)
+ {
+ hddLog(VOS_TRACE_LEVEL_FATAL,"%s: HDD Context Null Pointer", __func__);
+ VOS_ASSERT(0);
+ return NOTIFY_DONE;
+ }
+
+ hddLog(VOS_TRACE_LEVEL_INFO, "%s: %s New Net Device State = %lu",
+ __func__, dev->name, state);
switch (state) {
case NETDEV_REGISTER: