net/bnxt: add null check for resource manager
authorShahaji Bhosle <sbhosle@broadcom.com>
Fri, 11 Sep 2020 01:55:45 +0000 (18:55 -0700)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 18 Sep 2020 16:55:11 +0000 (18:55 +0200)
Verify the resource manager has been allocated prior to using it.
This can avoid potential segmentation faults.

Signed-off-by: Shahaji Bhosle <sbhosle@broadcom.com>
Reviewed-by: Mike Baucom <michael.baucom@broadcom.com>
Reviewed-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
drivers/net/bnxt/tf_core/tf_rm.c

index 9aec954..66a3358 100644 (file)
@@ -706,6 +706,8 @@ tf_rm_allocate(struct tf_rm_allocate_parms *parms)
        TF_CHECK_PARMS2(parms, parms->rm_db);
 
        rm_db = (struct tf_rm_new_db *)parms->rm_db;
+       if (!rm_db->db)
+               return -EINVAL;
        cfg_type = rm_db->db[parms->db_index].cfg_type;
 
        /* Bail out if not controlled by RM */
@@ -772,6 +774,8 @@ tf_rm_free(struct tf_rm_free_parms *parms)
        TF_CHECK_PARMS2(parms, parms->rm_db);
 
        rm_db = (struct tf_rm_new_db *)parms->rm_db;
+       if (!rm_db->db)
+               return -EINVAL;
        cfg_type = rm_db->db[parms->db_index].cfg_type;
 
        /* Bail out if not controlled by RM */
@@ -817,6 +821,8 @@ tf_rm_is_allocated(struct tf_rm_is_allocated_parms *parms)
        TF_CHECK_PARMS2(parms, parms->rm_db);
 
        rm_db = (struct tf_rm_new_db *)parms->rm_db;
+       if (!rm_db->db)
+               return -EINVAL;
        cfg_type = rm_db->db[parms->db_index].cfg_type;
 
        /* Bail out if not controlled by RM */
@@ -860,6 +866,8 @@ tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms)
        TF_CHECK_PARMS2(parms, parms->rm_db);
 
        rm_db = (struct tf_rm_new_db *)parms->rm_db;
+       if (!rm_db->db)
+               return -EINVAL;
        cfg_type = rm_db->db[parms->db_index].cfg_type;
 
        /* Bail out if not controlled by HCAPI */
@@ -883,6 +891,8 @@ tf_rm_get_hcapi_type(struct tf_rm_get_hcapi_parms *parms)
        TF_CHECK_PARMS2(parms, parms->rm_db);
 
        rm_db = (struct tf_rm_new_db *)parms->rm_db;
+       if (!rm_db->db)
+               return -EINVAL;
        cfg_type = rm_db->db[parms->db_index].cfg_type;
 
        /* Bail out if not controlled by HCAPI */
@@ -905,6 +915,8 @@ tf_rm_get_inuse_count(struct tf_rm_get_inuse_count_parms *parms)
        TF_CHECK_PARMS2(parms, parms->rm_db);
 
        rm_db = (struct tf_rm_new_db *)parms->rm_db;
+       if (!rm_db->db)
+               return -EINVAL;
        cfg_type = rm_db->db[parms->db_index].cfg_type;
 
        /* Bail out if not controlled by RM */
@@ -937,6 +949,8 @@ tf_rm_check_indexes_in_range(struct tf_rm_check_indexes_in_range_parms *parms)
        TF_CHECK_PARMS2(parms, parms->rm_db);
 
        rm_db = (struct tf_rm_new_db *)parms->rm_db;
+       if (!rm_db->db)
+               return -EINVAL;
        cfg_type = rm_db->db[parms->db_index].cfg_type;
 
        /* Bail out if not controlled by RM */