On 6/3/2025 6:49 PM, Dave Jiang wrote:
> 
> 
> 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.

I originally added this to the patchset during some initial development to 
handle possible
NULL dev pointers when updating soft reserve resources, see 
cxl_region_softreserv_update()
in patch 5/7.

In the current form of the that routine it appears we shouldn't execute the 
while loop
if dev is NULL so this could get from the patch set.

-Nathan 

> 
>>
>> Co-developed-by: Nathan Fontenot <nathan.fonte...@amd.com>
>> Signed-off-by: Nathan Fontenot <nathan.fonte...@amd.com>
>> Co-developed-by: Terry Bowman <terry.bow...@amd.com>
>> Signed-off-by: Terry Bowman <terry.bow...@amd.com>
>> Signed-off-by: Smita Koralahalli <smita.koralahallichannabasa...@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");
>>  
> 


Reply via email to