From: Shahaji Bhosle Date: Fri, 11 Sep 2020 01:55:45 +0000 (-0700) Subject: net/bnxt: add null check for resource manager X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=1f2b4fbd1673e0a88e2a3b0b00ea00591a823dae;p=dpdk.git net/bnxt: add null check for resource manager Verify the resource manager has been allocated prior to using it. This can avoid potential segmentation faults. Signed-off-by: Shahaji Bhosle Reviewed-by: Mike Baucom Reviewed-by: Ajit Khaparde --- diff --git a/drivers/net/bnxt/tf_core/tf_rm.c b/drivers/net/bnxt/tf_core/tf_rm.c index 9aec954dba..66a33583be 100644 --- a/drivers/net/bnxt/tf_core/tf_rm.c +++ b/drivers/net/bnxt/tf_core/tf_rm.c @@ -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 */