diff options
author | Vishal Verma <vishal.l.verma@intel.com> | 2022-06-02 09:44:27 -0600 |
---|---|---|
committer | Vishal Verma <vishal.l.verma@intel.com> | 2022-06-15 16:28:51 -0600 |
commit | 50e7a021314aa0365c9c85a359a31f26313fe93b (patch) | |
tree | 0005970d90f2ce9105f7b1932aa271da91244a95 | |
parent | 8186ec87dcd1b347ab0ee27ec5e87bda8c9a67e2 (diff) |
libcxl: fix a segfault when memdev->pmem is absent
A CXL memdev may not have any persistent capacity, and in this case it
is possible that a 'pmem' object never gets instantiated. Such a
scenario would cause free_pmem () to dereference a NULL pointer and
segfault.
Fix this by only proceeding in free_pmem() if 'pmem' was valid.
Link: https://lore.kernel.org/r/20220602154427.462852-1-vishal.l.verma@intel.com
Fixes: cd1aed6cefe8 ("libcxl: add representation for an nvdimm bridge object")
Cc: Dan Williams <dan.j.williams@intel.com>
Reported-by: Steven Garcia <steven.garcia@intel.com>
Tested-by: Steven Garcia <steven.garcia@intel.com>
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
-rw-r--r-- | cxl/lib/libcxl.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 374b0f13..c988ce2d 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -49,9 +49,11 @@ struct cxl_ctx { static void free_pmem(struct cxl_pmem *pmem) { - free(pmem->dev_buf); - free(pmem->dev_path); - free(pmem); + if (pmem) { + free(pmem->dev_buf); + free(pmem->dev_path); + free(pmem); + } } static void free_memdev(struct cxl_memdev *memdev, struct list_head *head) |