From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EE533A052E; Mon, 9 Mar 2020 18:04:01 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 277D51C02A; Mon, 9 Mar 2020 18:04:01 +0100 (CET) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id AB6541BFF4 for ; Mon, 9 Mar 2020 18:03:59 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Mar 2020 10:03:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,534,1574150400"; d="scan'208";a="245403924" Received: from jrharri1-skx.ch.intel.com ([143.182.137.73]) by orsmga006.jf.intel.com with ESMTP; 09 Mar 2020 10:03:58 -0700 From: Jim Harris To: dev@dpdk.org, bruce.richardson@intel.com Cc: Jim Harris Date: Mon, 9 Mar 2020 03:00:25 -0700 Message-Id: <20200309100025.9022-1-james.r.harris@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] contigmem: cleanup properly when load fails X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" If contigmem is not able to allocate all of the requested buffers, it frees whatever buffers were able to be allocated up until that point. But the pointers are not set to NULL in that case. After the load fails, the FreeBSD kernel will immediately call the contigmem unload handler, which tries to free the buffers again since the pointers were not set to NULL. It's not clear that we should just rely on the unload handler getting called after load failure. So let's keep the existing cleanup code in the load handler, but explicitly set the pointers to NULL after freeing them. Signed-off-by: Jim Harris --- kernel/freebsd/contigmem/contigmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/freebsd/contigmem/contigmem.c b/kernel/freebsd/contigmem/contigmem.c index 64e0a7fec..abb76f241 100644 --- a/kernel/freebsd/contigmem/contigmem.c +++ b/kernel/freebsd/contigmem/contigmem.c @@ -165,9 +165,11 @@ contigmem_load() error: for (i = 0; i < contigmem_num_buffers; i++) { - if (contigmem_buffers[i].addr != NULL) + if (contigmem_buffers[i].addr != NULL) { contigfree(contigmem_buffers[i].addr, contigmem_buffer_size, M_CONTIGMEM); + contigmem_buffers[i].addr = NULL; + } if (mtx_initialized(&contigmem_buffers[i].mtx)) mtx_destroy(&contigmem_buffers[i].mtx); } -- 2.20.1