[PATCH] drm/xe/xe_pmu: Add a null check for xe gt
Aravind Iddamsetty
aravind.iddamsetty at linux.intel.com
Wed Apr 16 09:26:48 UTC 2025
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)
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.
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;
More information about the Intel-xe
mailing list