diff mbox series

[v4,1/7] cxl/region: Avoid null pointer dereference in is_cxl_region()

Message ID 20250603221949.53272-2-Smita.KoralahalliChannabasappa@amd.com
State New
Headers show
Series Add managed SOFT RESERVE resource handling | expand

Commit Message

Smita Koralahalli June 3, 2025, 10:19 p.m. UTC
Add a NULL check in is_cxl_region() to prevent potential null pointer
dereference if a caller passes a NULL device. This change ensures the
function safely returns false instead of triggering undefined behavior
when dev is NULL.

Co-developed-by: Nathan Fontenot <Nathan.Fontenot@amd.com>
Signed-off-by: Nathan Fontenot <Nathan.Fontenot@amd.com>
Co-developed-by: Terry Bowman <terry.bowman@amd.com>
Signed-off-by: Terry Bowman <terry.bowman@amd.com>
Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
---
 drivers/cxl/core/region.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dave Jiang June 3, 2025, 11:49 p.m. UTC | #1
On 6/3/25 3:19 PM, Smita Koralahalli wrote:
> Add a NULL check in is_cxl_region() to prevent potential null pointer
> dereference if a caller passes a NULL device. This change ensures the
> function safely returns false instead of triggering undefined behavior
> when dev is NULL.

Don't think this change is necessary. The code paths should not be hitting any NULL region devices unless it's a programming error.

> 
> Co-developed-by: Nathan Fontenot <Nathan.Fontenot@amd.com>
> Signed-off-by: Nathan Fontenot <Nathan.Fontenot@amd.com>
> Co-developed-by: Terry Bowman <terry.bowman@amd.com>
> Signed-off-by: Terry Bowman <terry.bowman@amd.com>
> Signed-off-by: Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>
> ---
>  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 c3f4dc244df7..109b8a98c4c7 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -2333,7 +2333,7 @@ const struct device_type cxl_region_type = {
>  
>  bool is_cxl_region(struct device *dev)
>  {
> -	return dev->type == &cxl_region_type;
> +	return dev && dev->type == &cxl_region_type;
>  }
>  EXPORT_SYMBOL_NS_GPL(is_cxl_region, "CXL");
>
diff mbox series

Patch

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index c3f4dc244df7..109b8a98c4c7 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2333,7 +2333,7 @@  const struct device_type cxl_region_type = {
 
 bool is_cxl_region(struct device *dev)
 {
-	return dev->type == &cxl_region_type;
+	return dev && dev->type == &cxl_region_type;
 }
 EXPORT_SYMBOL_NS_GPL(is_cxl_region, "CXL");