raw/ifpga/base: check adapter pointer before dereference
authorWei Huang <wei.huang@intel.com>
Thu, 5 Nov 2020 02:05:40 +0000 (21:05 -0500)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 13 Nov 2020 15:26:54 +0000 (16:26 +0100)
In opae_adapter_destroy(), pointer "adapter" is not validated before
passing it to opae_adapter_shm_free() and opae_adapter_mutex_close()
which dereference it.

Coverity issue: 363752
Fixes: e41856b515ce ("raw/ifpga/base: enhance driver reliability in multi-process")

Signed-off-by: Wei Huang <wei.huang@intel.com>
Acked-by: Rosen Xu <rosen.xu@intel.com>
drivers/raw/ifpga/base/opae_hw_api.c

index 600afde..d5cd5fe 100644 (file)
@@ -605,10 +605,12 @@ int opae_adapter_enumerate(struct opae_adapter *adapter)
  */
 void opae_adapter_destroy(struct opae_adapter *adapter)
 {
-       if (adapter && adapter->ops && adapter->ops->destroy)
-               adapter->ops->destroy(adapter);
-       opae_adapter_shm_free(adapter);
-       opae_adapter_mutex_close(adapter);
+       if (adapter) {
+               if (adapter->ops && adapter->ops->destroy)
+                       adapter->ops->destroy(adapter);
+               opae_adapter_shm_free(adapter);
+               opae_adapter_mutex_close(adapter);
+       }
 }
 
 /**