Added checks for null pointers after memory allocation. Issues were reported by klocwork static analysis tool.
Fixes: 515e3608c741 ("ml/cnxk: configure OCM page size") Fixes: 4ff4ab8e1a20 ("ml/cnxk: support extended statistics") Signed-off-by: Srikanth Yalavarthi <syalavar...@marvell.com> --- drivers/ml/cnxk/cn10k_ml_ocm.c | 10 +++++++++- drivers/ml/cnxk/cn10k_ml_ops.c | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/ml/cnxk/cn10k_ml_ocm.c b/drivers/ml/cnxk/cn10k_ml_ocm.c index 1ea45b5b60..b9211b50a8 100644 --- a/drivers/ml/cnxk/cn10k_ml_ocm.c +++ b/drivers/ml/cnxk/cn10k_ml_ocm.c @@ -268,8 +268,12 @@ cn10k_ml_ocm_tilemask_find(struct rte_ml_dev *dev, uint8_t num_tiles, uint16_t w search_end_tile = start_tile; } - /* nibbles + prefix '0x' */ + /* allocate for local ocm mask */ local_ocm_mask = rte_zmalloc("local_ocm_mask", mldev->ocm.mask_words, RTE_CACHE_LINE_SIZE); + if (local_ocm_mask == NULL) { + plt_err("Unable to allocate memory for local_ocm_mask"); + return -1; + } tile_start = search_start_tile; start_search: @@ -494,6 +498,10 @@ cn10k_ml_ocm_print(struct rte_ml_dev *dev, FILE *fp) /* nibbles + prefix '0x' */ str = rte_zmalloc("ocm_mask_str", mldev->ocm.num_pages / 4 + 2, RTE_CACHE_LINE_SIZE); + if (str == NULL) { + plt_err("Unable to allocate memory for ocm_mask_str"); + return; + } fprintf(fp, "OCM State:\n"); for (tile_id = 0; tile_id < ocm->num_tiles; tile_id++) { diff --git a/drivers/ml/cnxk/cn10k_ml_ops.c b/drivers/ml/cnxk/cn10k_ml_ops.c index bf9409ad10..8d31276e8c 100644 --- a/drivers/ml/cnxk/cn10k_ml_ops.c +++ b/drivers/ml/cnxk/cn10k_ml_ops.c @@ -789,6 +789,11 @@ cn10k_ml_dev_configure(struct rte_ml_dev *dev, const struct rte_ml_dev_config *c /* Allocate memory for ocm_mask */ ocm->ocm_mask = rte_zmalloc("ocm_mask", ocm->mask_words * ocm->num_tiles, RTE_CACHE_LINE_SIZE); + if (ocm->ocm_mask == NULL) { + plt_err("Unable to allocate memory for OCM mask"); + ret = -ENOMEM; + goto error; + } for (tile_id = 0; tile_id < ocm->num_tiles; tile_id++) { ocm->tile_ocm_info[tile_id].ocm_mask = ocm->ocm_mask + tile_id * ocm->mask_words; @@ -1107,6 +1112,11 @@ cn10k_ml_dev_xstats_by_name_get(struct rte_ml_dev *dev, const char *name, uint16 num_xstats = PLT_DIM(cn10k_ml_model_xstats_table) * mldev->nb_models_loaded; xstats_map = rte_zmalloc("cn10k_ml_xstats_map", sizeof(struct rte_ml_dev_xstats_map) * num_xstats, 0); + if (xstats_map == NULL) { + plt_err("Unable to allocate memory for cn10k_ml_xstats_map"); + return -ENOMEM; + } + cn10k_ml_dev_xstats_names_get(dev, xstats_map, num_xstats); cn10k_ml_dev_info_get(dev, &dev_info); -- 2.17.1