[PATCH next] cxl/region: Fix an ERR_PTR() vs NULL bug

Dan Carpenter posted 1 patch 2 months, 2 weeks ago
drivers/cxl/core/region.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH next] cxl/region: Fix an ERR_PTR() vs NULL bug
Posted by Dan Carpenter 2 months, 2 weeks ago
The __cxl_decoder_detach() function is expected to return NULL on error
but this error path accidentally returns an error pointer.  It could
potentially lead to an error pointer dereference in the caller.  Change
it to return NULL.

Fixes: b3a88225519c ("cxl/region: Consolidate cxl_decoder_kill_region() and cxl_region_detach()")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/cxl/core/region.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index f0765a0af845..71cc42d05248 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2108,7 +2108,7 @@ __cxl_decoder_detach(struct cxl_region *cxlr,
 		if (pos >= p->interleave_ways) {
 			dev_dbg(&cxlr->dev, "position %d out of range %d\n",
 				pos, p->interleave_ways);
-			return ERR_PTR(-ENXIO);
+			return NULL;
 		}
 
 		if (!p->targets[pos])
-- 
2.47.2
Re: [PATCH next] cxl/region: Fix an ERR_PTR() vs NULL bug
Posted by Dave Jiang 2 months, 2 weeks ago

On 7/18/25 2:22 PM, Dan Carpenter wrote:
> The __cxl_decoder_detach() function is expected to return NULL on error
> but this error path accidentally returns an error pointer.  It could
> potentially lead to an error pointer dereference in the caller.  Change
> it to return NULL.
> 
> Fixes: b3a88225519c ("cxl/region: Consolidate cxl_decoder_kill_region() and cxl_region_detach()")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Thanks Dan!

Applied to cxl/next
49d6e658e758e42aaff8ae5ecdd2d06b29abf53e

> ---
>  drivers/cxl/core/region.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index f0765a0af845..71cc42d05248 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -2108,7 +2108,7 @@ __cxl_decoder_detach(struct cxl_region *cxlr,
>  		if (pos >= p->interleave_ways) {
>  			dev_dbg(&cxlr->dev, "position %d out of range %d\n",
>  				pos, p->interleave_ways);
> -			return ERR_PTR(-ENXIO);
> +			return NULL;
>  		}
>  
>  		if (!p->targets[pos])