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 488E445B1C; Sat, 12 Oct 2024 11:28:25 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 42441402D9; Sat, 12 Oct 2024 11:28:22 +0200 (CEST) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mails.dpdk.org (Postfix) with ESMTP id AC54940265 for ; Sat, 12 Oct 2024 11:28:19 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.19.162.112]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4XQdRw45HRz1SBhY; Sat, 12 Oct 2024 17:27:08 +0800 (CST) Received: from kwepemf500004.china.huawei.com (unknown [7.202.181.242]) by mail.maildlp.com (Postfix) with ESMTPS id 2E3B61402CA; Sat, 12 Oct 2024 17:28:18 +0800 (CST) Received: from localhost.localdomain (10.28.79.22) by kwepemf500004.china.huawei.com (7.202.181.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Sat, 12 Oct 2024 17:28:17 +0800 From: Jie Hai To: , , , Chengwen Feng , Kevin Laatz , Bruce Richardson CC: , Subject: [RESEND 2/2] dmadev: clean code for verify parameter Date: Sat, 12 Oct 2024 17:17:35 +0800 Message-ID: <20241012091735.24012-3-haijie1@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20241012091735.24012-1-haijie1@huawei.com> References: <20241012091735.24012-1-haijie1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemf500004.china.huawei.com (7.202.181.242) 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 From: Chengwen Feng Make sure to verify the 'dev_id' parameter before using them. Note: there is no actual problem with the current code, but it is recommended to clean it up. Cc: stable@dpdk.org Signed-off-by: Chengwen Feng --- lib/dmadev/rte_dmadev.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/dmadev/rte_dmadev.c b/lib/dmadev/rte_dmadev.c index 60c3d8ebf68e..4ba3b9380c5f 100644 --- a/lib/dmadev/rte_dmadev.c +++ b/lib/dmadev/rte_dmadev.c @@ -436,11 +436,12 @@ rte_dma_count_avail(void) int rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info) { - const struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; + const struct rte_dma_dev *dev; int ret; if (!rte_dma_is_valid(dev_id) || dev_info == NULL) return -EINVAL; + dev = &rte_dma_devices[dev_id]; if (*dev->dev_ops->dev_info_get == NULL) return -ENOTSUP; @@ -462,12 +463,13 @@ rte_dma_info_get(int16_t dev_id, struct rte_dma_info *dev_info) int rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf) { - struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; struct rte_dma_info dev_info; + struct rte_dma_dev *dev; int ret; if (!rte_dma_is_valid(dev_id) || dev_conf == NULL) return -EINVAL; + dev = &rte_dma_devices[dev_id]; if (dev->data->dev_started != 0) { RTE_DMA_LOG(ERR, @@ -513,11 +515,12 @@ rte_dma_configure(int16_t dev_id, const struct rte_dma_conf *dev_conf) int rte_dma_start(int16_t dev_id) { - struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; + struct rte_dma_dev *dev; int ret; if (!rte_dma_is_valid(dev_id)) return -EINVAL; + dev = &rte_dma_devices[dev_id]; if (dev->data->dev_conf.nb_vchans == 0) { RTE_DMA_LOG(ERR, "Device %d must be configured first", dev_id); @@ -545,11 +548,12 @@ rte_dma_start(int16_t dev_id) int rte_dma_stop(int16_t dev_id) { - struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; + struct rte_dma_dev *dev; int ret; if (!rte_dma_is_valid(dev_id)) return -EINVAL; + dev = &rte_dma_devices[dev_id]; if (dev->data->dev_started == 0) { RTE_DMA_LOG(WARNING, "Device %d already stopped", dev_id); @@ -572,11 +576,12 @@ rte_dma_stop(int16_t dev_id) int rte_dma_close(int16_t dev_id) { - struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; + struct rte_dma_dev *dev; int ret; if (!rte_dma_is_valid(dev_id)) return -EINVAL; + dev = &rte_dma_devices[dev_id]; /* Device must be stopped before it can be closed */ if (dev->data->dev_started == 1) { @@ -600,13 +605,14 @@ int rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan, const struct rte_dma_vchan_conf *conf) { - struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; struct rte_dma_info dev_info; bool src_is_dev, dst_is_dev; + struct rte_dma_dev *dev; int ret; if (!rte_dma_is_valid(dev_id) || conf == NULL) return -EINVAL; + dev = &rte_dma_devices[dev_id]; if (dev->data->dev_started != 0) { RTE_DMA_LOG(ERR, @@ -693,10 +699,11 @@ rte_dma_vchan_setup(int16_t dev_id, uint16_t vchan, int rte_dma_stats_get(int16_t dev_id, uint16_t vchan, struct rte_dma_stats *stats) { - const struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; + const struct rte_dma_dev *dev; if (!rte_dma_is_valid(dev_id) || stats == NULL) return -EINVAL; + dev = &rte_dma_devices[dev_id]; if (vchan >= dev->data->dev_conf.nb_vchans && vchan != RTE_DMA_ALL_VCHAN) { @@ -715,11 +722,12 @@ rte_dma_stats_get(int16_t dev_id, uint16_t vchan, struct rte_dma_stats *stats) int rte_dma_stats_reset(int16_t dev_id, uint16_t vchan) { - struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; + struct rte_dma_dev *dev; int ret; if (!rte_dma_is_valid(dev_id)) return -EINVAL; + dev = &rte_dma_devices[dev_id]; if (vchan >= dev->data->dev_conf.nb_vchans && vchan != RTE_DMA_ALL_VCHAN) { @@ -739,10 +747,11 @@ rte_dma_stats_reset(int16_t dev_id, uint16_t vchan) int rte_dma_vchan_status(int16_t dev_id, uint16_t vchan, enum rte_dma_vchan_status *status) { - struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; + struct rte_dma_dev *dev; if (!rte_dma_is_valid(dev_id) || status == NULL) return -EINVAL; + dev = &rte_dma_devices[dev_id]; if (vchan >= dev->data->dev_conf.nb_vchans) { RTE_DMA_LOG(ERR, "Device %u vchan %u out of range", dev_id, vchan); @@ -804,12 +813,13 @@ dma_dump_capability(FILE *f, uint64_t dev_capa) int rte_dma_dump(int16_t dev_id, FILE *f) { - const struct rte_dma_dev *dev = &rte_dma_devices[dev_id]; + const struct rte_dma_dev *dev; struct rte_dma_info dev_info; int ret; if (!rte_dma_is_valid(dev_id) || f == NULL) return -EINVAL; + dev = &rte_dma_devices[dev_id]; ret = rte_dma_info_get(dev_id, &dev_info); if (ret != 0) { -- 2.22.0