From patchwork Wed Oct 9 21:13:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hernan Vargas X-Patchwork-Id: 145565 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B5B4745AF8; Wed, 9 Oct 2024 23:18:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3D1CC40671; Wed, 9 Oct 2024 23:18:00 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mails.dpdk.org (Postfix) with ESMTP id 33DCB402EF for ; Wed, 9 Oct 2024 23:17:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728508665; x=1760044665; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+JNNn4KFmZ9TUszcnvRICTpCSDSLNPJFLpvtDmFFw1M=; b=kra+tpV9Dhg6iJeRSk1DJO/zXSYUjJaE/dnjtmRRMgTqkBgWrefJR8o8 Rlnj6PUMUSs32a83pUkZ5tHbSfsZPldTX5Ha3tnX0CMhfOTVrnxm3Q1M9 oI0W+qPmxz8czrOazfKi1d1O2C3m9/T5Pm0EGrtjogwomN6ysry7jPLSJ PZ8/tL/2zeR0HvxgyhvWS3CA6xSezJhSejMcLDZkOsAQ+hxeXFbeEn9AX 5HduPkLuuJWx0mhSQlZVIeDTk36+febaM1UEEDlob8BOb3A/hcfvUQ+JU Mv1wYsmdPB6NgBqBy2r0hkof3aggqkCDqMY4ULe+D1wohGbruvNNEz3Lw w==; X-CSE-ConnectionGUID: jVpGYAE7RUWEDXzH5g1EAQ== X-CSE-MsgGUID: zVcrf0TOTt6lGA3tuz8A4Q== X-IronPort-AV: E=McAfee;i="6700,10204,11220"; a="39202252" X-IronPort-AV: E=Sophos;i="6.11,190,1725346800"; d="scan'208";a="39202252" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Oct 2024 14:17:45 -0700 X-CSE-ConnectionGUID: MIxnPjEISxWNByo65DXDnw== X-CSE-MsgGUID: 3CUIh2LOTBCHeBTmTJbfpA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,190,1725346800"; d="scan'208";a="76480627" Received: from unknown (HELO csl-npg-qt0.la.intel.com) ([10.233.181.103]) by fmviesa008.fm.intel.com with ESMTP; 09 Oct 2024 14:17:44 -0700 From: Hernan Vargas To: dev@dpdk.org, gakhil@marvell.com, trix@redhat.com, maxime.coquelin@redhat.com Cc: nicolas.chautru@intel.com, qi.z.zhang@intel.com, Hernan Vargas Subject: [PATCH v3 11/12] baseband/acc: rte free refactor Date: Wed, 9 Oct 2024 14:13:01 -0700 Message-Id: <20241009211302.177471-12-hernan.vargas@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20241009211302.177471-1-hernan.vargas@intel.com> References: <20241009211302.177471-1-hernan.vargas@intel.com> MIME-Version: 1.0 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 Refactor to explicitly set pointer to NULL after free to avoid double free. Signed-off-by: Hernan Vargas Reviewed-by: Maxime Coquelin --- drivers/baseband/acc/rte_acc100_pmd.c | 23 +++++++------ drivers/baseband/acc/rte_vrb_pmd.c | 48 +++++++++++++++------------ 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/drivers/baseband/acc/rte_acc100_pmd.c b/drivers/baseband/acc/rte_acc100_pmd.c index c82a0b6cc174..d33e42c8070b 100644 --- a/drivers/baseband/acc/rte_acc100_pmd.c +++ b/drivers/baseband/acc/rte_acc100_pmd.c @@ -564,6 +564,7 @@ acc100_setup_queues(struct rte_bbdev *dev, uint16_t num_queues, int socket_id) d->tail_ptrs = NULL; free_sw_rings: rte_free(d->sw_rings_base); + d->sw_rings_base = NULL; d->sw_rings = NULL; return ret; @@ -593,6 +594,7 @@ acc100_intr_enable(struct rte_bbdev *dev) "Couldn't enable interrupts for device: %s", dev->data->name); rte_free(d->info_ring); + d->info_ring = NULL; return ret; } ret = rte_intr_callback_register(dev->intr_handle, @@ -602,6 +604,7 @@ acc100_intr_enable(struct rte_bbdev *dev) "Couldn't register interrupt callback for device: %s", dev->data->name); rte_free(d->info_ring); + d->info_ring = NULL; return ret; } @@ -619,16 +622,15 @@ acc100_dev_close(struct rte_bbdev *dev) { struct acc_device *d = dev->data->dev_private; acc100_check_ir(d); - if (d->sw_rings_base != NULL) { - rte_free(d->tail_ptrs); - rte_free(d->info_ring); - rte_free(d->sw_rings_base); - rte_free(d->harq_layout); - d->sw_rings_base = NULL; - d->tail_ptrs = NULL; - d->info_ring = NULL; - d->harq_layout = NULL; - } + rte_free(d->tail_ptrs); + rte_free(d->info_ring); + rte_free(d->sw_rings_base); + rte_free(d->harq_layout); + d->tail_ptrs = NULL; + d->info_ring = NULL; + d->sw_rings_base = NULL; + d->sw_rings = NULL; + d->harq_layout = NULL; /* Ensure all in flight HW transactions are completed */ usleep(ACC_LONG_WAIT); return 0; @@ -4235,6 +4237,7 @@ poweron_cleanup(struct rte_bbdev *bbdev, struct acc_device *d, rte_bbdev_log(INFO, "Number of 5GUL engines %d", numEngines); rte_free(d->sw_rings_base); + d->sw_rings_base = NULL; usleep(ACC_LONG_WAIT); } diff --git a/drivers/baseband/acc/rte_vrb_pmd.c b/drivers/baseband/acc/rte_vrb_pmd.c index c0464d20c641..03df270af1cf 100644 --- a/drivers/baseband/acc/rte_vrb_pmd.c +++ b/drivers/baseband/acc/rte_vrb_pmd.c @@ -745,10 +745,13 @@ vrb_setup_queues(struct rte_bbdev *dev, uint16_t num_queues, int socket_id) free_sw_rings: if (d->device_variant == VRB1_VARIANT) { rte_free(d->sw_rings_base); + d->sw_rings_base = NULL; d->sw_rings = NULL; } else if (d->device_variant == VRB2_VARIANT) { - for (i = 0; i <= RTE_BBDEV_OP_MLDTS; i++) + for (i = 0; i <= RTE_BBDEV_OP_MLDTS; i++) { rte_free(d->sw_rings_array[i]); + d->sw_rings_array[i] = 0; + } } return ret; @@ -786,6 +789,7 @@ vrb_intr_enable(struct rte_bbdev *dev) "Couldn't enable interrupts for device: %s", dev->data->name); rte_free(d->info_ring); + d->info_ring = NULL; return ret; } ret = rte_intr_callback_register(dev->intr_handle, @@ -795,6 +799,7 @@ vrb_intr_enable(struct rte_bbdev *dev) "Couldn't register interrupt callback for device: %s", dev->data->name); rte_free(d->info_ring); + d->info_ring = NULL; return ret; } @@ -849,6 +854,7 @@ vrb_intr_enable(struct rte_bbdev *dev) "Couldn't enable interrupts for device: %s", dev->data->name); rte_free(d->info_ring); + d->info_ring = NULL; return ret; } ret = rte_intr_callback_register(dev->intr_handle, @@ -858,6 +864,7 @@ vrb_intr_enable(struct rte_bbdev *dev) "Couldn't register interrupt callback for device: %s", dev->data->name); rte_free(d->info_ring); + d->info_ring = NULL; return ret; } @@ -878,28 +885,25 @@ vrb_dev_close(struct rte_bbdev *dev) vrb_check_ir(d); if (d->device_variant == VRB1_VARIANT) { - if (d->sw_rings_base != NULL) { - rte_free(d->tail_ptrs); - rte_free(d->info_ring); - rte_free(d->sw_rings_base); - rte_free(d->harq_layout); - d->tail_ptrs = NULL; - d->info_ring = NULL; - d->sw_rings_base = NULL; - d->harq_layout = NULL; - } + rte_free(d->tail_ptrs); + rte_free(d->info_ring); + rte_free(d->sw_rings_base); + rte_free(d->harq_layout); + d->tail_ptrs = NULL; + d->info_ring = NULL; + d->sw_rings_base = NULL; + d->sw_rings = NULL; + d->harq_layout = NULL; } else if (d->device_variant == VRB2_VARIANT) { - if (d->sw_rings_array[1] != NULL) { - rte_free(d->tail_ptrs); - rte_free(d->info_ring); - rte_free(d->harq_layout); - d->tail_ptrs = NULL; - d->info_ring = NULL; - d->harq_layout = NULL; - for (i = 0; i <= RTE_BBDEV_OP_MLDTS; i++) { - rte_free(d->sw_rings_array[i]); - d->sw_rings_array[i] = NULL; - } + rte_free(d->tail_ptrs); + rte_free(d->info_ring); + rte_free(d->harq_layout); + d->tail_ptrs = NULL; + d->info_ring = NULL; + d->harq_layout = NULL; + for (i = 0; i <= RTE_BBDEV_OP_MLDTS; i++) { + rte_free(d->sw_rings_array[i]); + d->sw_rings_array[i] = NULL; } } /* Ensure all in flight HW transactions are completed. */