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 D26D745450; Wed, 19 Jun 2024 01:25:21 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 935604026C; Wed, 19 Jun 2024 01:25:21 +0200 (CEST) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) by mails.dpdk.org (Postfix) with ESMTP id 7256A4021D for ; Wed, 19 Jun 2024 01:25:20 +0200 (CEST) Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-6bfd4b88608so4319295a12.1 for ; Tue, 18 Jun 2024 16:25:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1718753119; x=1719357919; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0IZ4k0oE6+8l1/3FQpowdq3fIiK0NojbMgdIvAlpetQ=; b=0N3L48f266Ubf5Vvlq7MyKyj6oVnNQCTBPLkWMMdXdKI55SRyOiiW4nWy/sKeIqKV0 1ZO4GfV8uCnFs78rk6hIsTCaTN4yelB5zIcORQwCuF09w0ANg3ZjXMUhCyOOdrbU/q0f 5CX1hhKmkI6r9krhsFN4GYXJkyf0ZlnCzamBAawOrjkHJ6e1VmE1IukuXb0DHb/kIcqb uLIr6UDj5wBBhna0HqOIPOmxoLeTcqRP9x+zqPLLKv5eanSDRV/DhSJ4bbn3b+WANXB4 aTgq6nzvKAoRCqmSbl+flbZjRNulaij7ZwFtuImUc44okZp7Yy824IQ7VudAsxFs4vPp OTXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718753119; x=1719357919; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0IZ4k0oE6+8l1/3FQpowdq3fIiK0NojbMgdIvAlpetQ=; b=F5ziEe787jFD5TamDvN4Rrx1iK+XjOo7vwJ44f1fyB/V+zWjvjY2+U+csJmK73dEzu 8uEN8iiOws8UeglG66RQNXPpO24JUva0G6bdxCkts9FWfllc7mWvPem8C5tksqmDT87i +C+3CHKoFVyIjNf/uurLyNqiJZqzm3LbVYtgMyw3m1eH84RMUbZIEUbQ+fh3KxnZPBua 0OpxjBp3KokvUhET4diPKJRJjXdoOsES0nDaaLV46zQwAiNsJyRXBABQhclPz0B4lGHP zs8qjm0RJckVrT0aMQffcS5oOTcPosEAFS8Y51BYR4zFGeKIIDQiuNfH+DDeqBKs/9M4 Wn2Q== X-Gm-Message-State: AOJu0YyQj9h8O+PlOErekL0D7bCMtJNM3VhfKd61PzOAWvcba4TEqjDH GPFYdbIHIU60JI02YkP9mI8hvL+hJ6kPgjsFSu35fP9xofEXoyL7Fvf471MY4vn3HyE0QzPejUH W X-Google-Smtp-Source: AGHT+IH50OPNCDAgf1KrI2A4h9OjiB7lf9UKtfapzmNtdCdYMbRHb7FrAn8oxIclHt8LVXbEBQ68WA== X-Received: by 2002:a05:6a20:24a4:b0:1b7:7d3b:dd98 with SMTP id adf61e73a8af0-1bcbb5cb13emr901954637.41.1718753119526; Tue, 18 Jun 2024 16:25:19 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-705ccb3d268sm9459096b3a.101.2024.06.18.16.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jun 2024 16:25:19 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Srikanth Yalavarthi , Kai Ji , Pablo de Lara , Chengwen Feng , Jeroen de Borst , Rushil Gupta , Joshua Washington , Devendra Singh Rawat , Alok Prasad , Jochen Behrens , Reshma Pattan Subject: [PATCH] memzone: remove unnecessary null checks Date: Tue, 18 Jun 2024 16:25:08 -0700 Message-ID: <20240618232508.21045-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The function rte_memzone_free() already checks if the argument is NULL. Add it to the coccinelle fix script and correct all the existing code. Signed-off-by: Stephen Hemminger --- app/test-mldev/test_inference_common.c | 6 ++---- devtools/cocci/nullfree.cocci | 3 +++ drivers/crypto/ipsec_mb/ipsec_mb_ops.c | 3 +-- drivers/dma/hisilicon/hisi_dmadev.c | 3 +-- drivers/net/gve/gve_ethdev.c | 3 +-- drivers/net/qede/qede_filter.c | 3 +-- drivers/net/vmxnet3/vmxnet3_ethdev.c | 3 +-- lib/latencystats/rte_latencystats.c | 3 +-- 8 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/test-mldev/test_inference_common.c b/app/test-mldev/test_inference_common.c index 36629210ee..3b77f37010 100644 --- a/app/test-mldev/test_inference_common.c +++ b/app/test-mldev/test_inference_common.c @@ -870,8 +870,7 @@ ml_inference_iomem_setup(struct ml_test *test, struct ml_options *opt, uint16_t return 0; error: - if (mz != NULL) - rte_memzone_free(mz); + rte_memzone_free(mz); if (t->model[fid].io_pool != NULL) { rte_mempool_free(t->model[fid].io_pool); @@ -895,8 +894,7 @@ ml_inference_iomem_destroy(struct ml_test *test, struct ml_options *opt, uint16_ /* release user data memzone */ sprintf(mz_name, "ml_user_data_%d", fid); mz = rte_memzone_lookup(mz_name); - if (mz != NULL) - rte_memzone_free(mz); + rte_memzone_free(mz); /* destroy io pool */ sprintf(mp_name, "ml_io_pool_%d", fid); diff --git a/devtools/cocci/nullfree.cocci b/devtools/cocci/nullfree.cocci index c58aad4fb7..c0526a2a3f 100644 --- a/devtools/cocci/nullfree.cocci +++ b/devtools/cocci/nullfree.cocci @@ -73,6 +73,9 @@ expression E; - if (E != NULL) rte_mempool_free(E); + rte_mempool_free(E); | +- if (E != NULL) rte_memzone_free(E); ++ rte_memzone_free(E); +| - if (E != NULL) rte_pktmbuf_free(E); + rte_pktmbuf_free(E); | diff --git a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c index f21f9cc5a0..ba899604d2 100644 --- a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c +++ b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c @@ -336,8 +336,7 @@ ipsec_mb_qp_setup(struct rte_cryptodev *dev, uint16_t qp_id, #else if (rte_eal_process_type() == RTE_PROC_SECONDARY) return ret; - if (qp->mb_mgr_mz) - rte_memzone_free(qp->mb_mgr_mz); + rte_memzone_free(qp->mb_mgr_mz); #endif rte_free(qp); return ret; diff --git a/drivers/dma/hisilicon/hisi_dmadev.c b/drivers/dma/hisilicon/hisi_dmadev.c index 22303e7bef..e96bc1d654 100644 --- a/drivers/dma/hisilicon/hisi_dmadev.c +++ b/drivers/dma/hisilicon/hisi_dmadev.c @@ -310,8 +310,7 @@ hisi_dma_alloc_iomem(struct hisi_dma_dev *hw, uint16_t ring_size, static void hisi_dma_free_iomem(struct hisi_dma_dev *hw) { - if (hw->iomz != NULL) - rte_memzone_free(hw->iomz); + rte_memzone_free(hw->iomz); hw->iomz = NULL; hw->sqe = NULL; diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c index 475745b9c0..0b29317497 100644 --- a/drivers/net/gve/gve_ethdev.c +++ b/drivers/net/gve/gve_ethdev.c @@ -77,8 +77,7 @@ gve_free_qpls(struct gve_priv *priv) return; for (i = 0; i < nb_txqs + nb_rxqs; i++) { - if (priv->qpl[i].mz != NULL) - rte_memzone_free(priv->qpl[i].mz); + rte_memzone_free(priv->qpl[i].mz); rte_free(priv->qpl[i].page_buses); } diff --git a/drivers/net/qede/qede_filter.c b/drivers/net/qede/qede_filter.c index e547b24a73..d98266eac5 100644 --- a/drivers/net/qede/qede_filter.c +++ b/drivers/net/qede/qede_filter.c @@ -158,8 +158,7 @@ void qede_fdir_dealloc_resc(struct rte_eth_dev *eth_dev) SLIST_FOREACH(tmp, &qdev->arfs_info.arfs_list_head, list) { if (tmp) { - if (tmp->mz) - rte_memzone_free(tmp->mz); + rte_memzone_free(tmp->mz); SLIST_REMOVE(&qdev->arfs_info.arfs_list_head, tmp, qede_arfs_entry, list); rte_free(tmp); diff --git a/drivers/net/vmxnet3/vmxnet3_ethdev.c b/drivers/net/vmxnet3/vmxnet3_ethdev.c index ce7c347254..467fb61137 100644 --- a/drivers/net/vmxnet3/vmxnet3_ethdev.c +++ b/drivers/net/vmxnet3/vmxnet3_ethdev.c @@ -189,8 +189,7 @@ gpa_zone_reserve(struct rte_eth_dev *dev, uint32_t size, mz = rte_memzone_lookup(z_name); if (!reuse) { - if (mz) - rte_memzone_free(mz); + rte_memzone_free(mz); return rte_memzone_reserve_aligned(z_name, size, socket_id, RTE_MEMZONE_IOVA_CONTIG, align); } diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c index cae4b50878..3bec205427 100644 --- a/lib/latencystats/rte_latencystats.c +++ b/lib/latencystats/rte_latencystats.c @@ -336,8 +336,7 @@ rte_latencystats_uninit(void) /* free up the memzone */ mz = rte_memzone_lookup(MZ_RTE_LATENCY_STATS); - if (mz) - rte_memzone_free(mz); + rte_memzone_free(mz); return 0; } -- 2.43.0