Skip to content

Commit

Permalink
cxl/list: tidy the error path in add_cxl_decoder()
Browse files Browse the repository at this point in the history
Static analysis reported this NULL pointer dereference during
cleanup on error in add_cxl_decoder().

Link: https://lore.kernel.org/r/[email protected]
Fixes: 4656497 ("cxl/list: Add decoder support")
Signed-off-by: Alison Schofield <[email protected]>
Signed-off-by: Vishal Verma <[email protected]>
  • Loading branch information
AlisonSchofield authored and stellarhopper committed Mar 4, 2022
1 parent 057ca6f commit 367593e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cxl/lib/libcxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 367593e

Please sign in to comment.