From 2c512ff1698a1726dad605e13005aa3b7c0070c2 Mon Sep 17 00:00:00 2001 From: Nirmoy Das Date: Fri, 3 Jul 2026 07:02:34 -0700 Subject: [PATCH] NVIDIA: VR: SAUCE: cxl: Guard unlinked memdev endpoints cxlmd->endpoint starts as ERR_PTR(-ENXIO) until endpoint port registration links the memdev to a real cxl_port. Treat NULL and error pointers as "endpoint not linked" before dereferencing cxlmd->endpoint in CXL helper paths. The BOS region-management backport exposes these helpers before endpoint linkage. This backports commit aff4ccee4530 ("NVIDIA: VR: SAUCE: cxl: Guard unlinked memdev endpoints"). Its PCI hunk is omitted because BOS already guards cxl_reset_done(). Fixes: 29317f8dc6ed ("cxl/mem: Introduce cxl_memdev_attach for CXL-dependent operation") Signed-off-by: Nirmoy Das --- drivers/cxl/core/hdm.c | 6 +++++- drivers/cxl/core/region.c | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/cxl/core/hdm.c b/drivers/cxl/core/hdm.c index 603cc746aa497..e0d084267a7aa 100644 --- a/drivers/cxl/core/hdm.c +++ b/drivers/cxl/core/hdm.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "cxlmem.h" #include "core.h" @@ -617,6 +618,9 @@ cxl_find_free_decoder(struct cxl_memdev *cxlmd) struct cxl_port *endpoint = cxlmd->endpoint; struct device *dev; + if (IS_ERR_OR_NULL(endpoint)) + return NULL; + guard(rwsem_read)(&cxl_rwsem.dpa); dev = device_find_child(&endpoint->dev, NULL, find_free_decoder); if (!dev) @@ -759,7 +763,7 @@ struct cxl_endpoint_decoder *cxl_get_committed_decoder(struct cxl_memdev *cxlmd, struct cxl_endpoint_decoder *cxled; struct device *cxled_dev; - if (!endpoint) + if (IS_ERR_OR_NULL(endpoint)) return NULL; guard(rwsem_read)(&cxl_rwsem.dpa); diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e820fb63b95aa..a7062a502f88a 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -814,7 +815,7 @@ struct cxl_root_decoder *cxl_get_hpa_freespace(struct cxl_memdev *cxlmd, struct cxl_port *endpoint; endpoint = cxlmd->endpoint; - if (!endpoint) { + if (IS_ERR_OR_NULL(endpoint)) { dev_dbg(&cxlmd->dev, "endpoint not linked to memdev\n"); return ERR_PTR(-ENXIO); } @@ -3172,7 +3173,8 @@ struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa) .dpa = dpa, }; port = cxlmd->endpoint; - if (port && is_cxl_endpoint(port) && cxl_num_decoders_committed(port)) + if (!IS_ERR_OR_NULL(port) && is_cxl_endpoint(port) && + cxl_num_decoders_committed(port)) device_for_each_child(&port->dev, &ctx, __cxl_dpa_to_region); return ctx.cxlr;