From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 53E8041EB5; Thu, 16 Mar 2023 22:29:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B3E6942DBF; Thu, 16 Mar 2023 22:29:41 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 6869A42DB3 for ; Thu, 16 Mar 2023 22:29:38 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32GG041Q005830 for ; Thu, 16 Mar 2023 14:29:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=pfpt0220; bh=i5GgR1NxcfTPqcvHkYHk403KelJJB7nucMeiJ3TfF18=; b=KV9ePjwVSZ6IxPuj7ERzb/QWbSNpU0Cul6XYCxk1hdKQJw2tqJY4zJOaCp3cfTLyHBWQ n7m6uHJ4n48rsidq9etRFjrpN4YroxHlSxC1UtSHAUk8iDZyulkwwWk1Bi8Y5wQF94cX gA26jhHcBGDnQIVo57K6QrUOYk6lTtiYW4as9TLFTAD6ybq6nyBhgzLYKPjYpvFKwFhg 0YSRz4eprqbGEoAwT/IY71WJv/1e8kOZY+KdYH8/QyO/gDeAeN8H/pdjI3EtBlS0dR/d anGFuy0DZXhEwJrEhEuW3uEu8li40OP7dcHARS28NBV7bPWnVoOw2WjoYE5LC0rJuW5o pQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3pbxq2ucrj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 16 Mar 2023 14:29:37 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Thu, 16 Mar 2023 14:29:35 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Thu, 16 Mar 2023 14:29:35 -0700 Received: from ml-host-33.caveonetworks.com (unknown [10.110.143.233]) by maili.marvell.com (Postfix) with ESMTP id 9DE4C3F707D; Thu, 16 Mar 2023 14:29:35 -0700 (PDT) From: Srikanth Yalavarthi To: Srikanth Yalavarthi , Prince Takkar , Shivah Shankar S CC: , , Subject: [PATCH v3 3/8] ml/cnxk: add pointer check after memory allocation Date: Thu, 16 Mar 2023 14:28:59 -0700 Message-ID: <20230316212904.9318-4-syalavarthi@marvell.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230316212904.9318-1-syalavarthi@marvell.com> References: <20230315135427.11489-1-syalavarthi@marvell.com> <20230316212904.9318-1-syalavarthi@marvell.com> MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-GUID: iCB_PgqwvHHqg4uH-MxA-jYkZd6jzpP5 X-Proofpoint-ORIG-GUID: iCB_PgqwvHHqg4uH-MxA-jYkZd6jzpP5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-16_14,2023-03-16_02,2023-02-09_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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