[PATCH] drm/xe/xe_pmu: Add a null check for xe gt

Riana Tauro riana.tauro at intel.com
Wed Apr 16 14:36:41 UTC 2025


Hi Aravind

On 4/16/2025 2:56 PM, Aravind Iddamsetty wrote:
> 
> On 16-04-2025 11:35, Riana Tauro wrote:
>> The PMU initialization function exits if gt is invalid,
>> eliminating the need for additional checks. However, absence
>> of these checks causes static analysis tool warnings
>>
>> Add a null check for gt to avoid static analysis tool warnings
>>
>> Signed-off-by: Riana Tauro <riana.tauro at intel.com>
>> ---
>>   drivers/gpu/drm/xe/xe_pmu.c | 7 ++++---
>>   1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_pmu.c b/drivers/gpu/drm/xe/xe_pmu.c
>> index 69df0e3520a5..5550ed30018f 100644
>> --- a/drivers/gpu/drm/xe/xe_pmu.c
>> +++ b/drivers/gpu/drm/xe/xe_pmu.c
>> @@ -141,6 +141,8 @@ static bool event_gt_forcewake(struct perf_event *event)
>>   		return true;
>>   
>>   	gt = xe_device_get_gt(xe, config_to_gt_id(config));
>> +	if (!gt)
>> +		return false;
> 
> this looks fine, but I doubt if we will reach to this stage if wrong GT
> is passed, it shall fail at this
> check event_supported(pmu, gt, id)
yeah it will never reach this stage. perf_event_open will return inval
incase gt in configid is wrong.

This is just to silence the static analysis warnings

> 
> same should be the case for below as well, non supported even't would
> fail the event init so it should not
> reach to xe_pmu_event_destroy.
> 
> but having said that i doubt if xe_device_get_gt would ever return NULL,
> as that would mean primary_gt or media_gt
> failed intialization, if it happens the driver would fail in load,
> wouldn't come to this stage.

Need to check why this function is returning NULL, that's the reason
the tool is complaining about null check missing

Thanks
Riana

> 
> Thanks,
> Aravind.
>>   
>>   	fw_ref = kzalloc(sizeof(*fw_ref), GFP_KERNEL);
>>   	if (!fw_ref)
>> @@ -211,11 +213,10 @@ static bool event_param_valid(struct perf_event *event)
>>   static void xe_pmu_event_destroy(struct perf_event *event)
>>   {
>>   	struct xe_device *xe = container_of(event->pmu, typeof(*xe), pmu.base);
>> -	struct xe_gt *gt;
>>   	unsigned int *fw_ref = event->pmu_private;
>> +	struct xe_gt *gt = xe_device_get_gt(xe, config_to_gt_id(event->attr.config));
>>   
>> -	if (fw_ref) {
>> -		gt = xe_device_get_gt(xe, config_to_gt_id(event->attr.config));
>> +	if (fw_ref && gt) {
>>   		xe_force_wake_put(gt_to_fw(gt), *fw_ref);
>>   		kfree(fw_ref);
>>   		event->pmu_private = NULL;
Ne


More information about the Intel-xe mailing list