From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DATE_IN_PAST_06_12, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76FEFC10F29 for ; Mon, 9 Mar 2020 17:04:02 +0000 (UTC) Received: from dpdk.org (dpdk.org [92.243.14.124]) by mail.kernel.org (Postfix) with ESMTP id 41E542465D for ; Mon, 9 Mar 2020 17:04:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 41E542465D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=dev-bounces@dpdk.org 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