diff mbox series

[ndctl] cxl/list: tidy the error path in add_cxl_decoder()

Message ID 20220304005423.1054282-1-alison.schofield@intel.com (mailing list archive)
State Accepted
Commit 367593e7b602fd490baf22a26887c09877e75c14
Headers show
Series [ndctl] cxl/list: tidy the error path in add_cxl_decoder() | expand

Commit Message

Alison Schofield March 4, 2022, 12:54 a.m. UTC
From: Alison Schofield <alison.schofield@intel.com>

Static analysis reported this NULL pointer dereference during
cleanup on error in add_cxl_decoder().

Fixes: 46564977afb7 ("cxl/list: Add decoder support")
Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 cxl/lib/libcxl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)


base-commit: 3b5fb8b6428dfaab39bab58d67412427f514c1f4
diff mbox series

Patch

diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index daa2bbc5a299..27c9e2ef8bc5 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -919,11 +919,11 @@  static void *add_cxl_decoder(void *parent, int id, const char *cxldecoder_base)
 
 	decoder->dev_path = strdup(cxldecoder_base);
 	if (!decoder->dev_path)
-		goto err;
+		goto err_decoder;
 
 	decoder->dev_buf = calloc(1, strlen(cxldecoder_base) + 50);
 	if (!decoder->dev_buf)
-		goto err;
+		goto err_decoder;
 	decoder->buf_len = strlen(cxldecoder_base) + 50;
 
 	sprintf(path, "%s/start", cxldecoder_base);
@@ -1024,10 +1024,12 @@  static void *add_cxl_decoder(void *parent, int id, const char *cxldecoder_base)
 	list_add(&port->decoders, &decoder->list);
 
 	return decoder;
-err:
+
+err_decoder:
 	free(decoder->dev_path);
 	free(decoder->dev_buf);
 	free(decoder);
+err:
 	free(path);
 	return NULL;
 }