DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jim Harris <james.r.harris@intel.com>
To: dev@dpdk.org, bruce.richardson@intel.com
Cc: Jim Harris <james.r.harris@intel.com>
Subject: [dpdk-dev] [PATCH] contigmem: cleanup properly when load fails
Date: Mon,  9 Mar 2020 03:00:25 -0700	[thread overview]
Message-ID: <20200309100025.9022-1-james.r.harris@intel.com> (raw)

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 <james.r.harris@intel.com>
---
 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


             reply	other threads:[~2020-03-09 17:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-09 10:00 Jim Harris [this message]
2020-03-10  9:31 ` Bruce Richardson
2020-03-19 12:54   ` David Marchand
2020-03-19 13:52     ` Harris, James R
2020-03-19 14:41   ` David Marchand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200309100025.9022-1-james.r.harris@intel.com \
    --to=james.r.harris@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).