From 0146cd80a542fdddfcb4d6c42b597bf81ef9c960 Mon Sep 17 00:00:00 2001 From: jsg Date: Tue, 13 Jun 2023 03:29:00 +0000 Subject: [PATCH] drm/amd/pm: avoid potential UBSAN issue on legacy asics From Guchun Chen 506da05a5e0fa46e048606581dd8bf3fe0161ab2 in linux-6.1.y/6.1.29 5247f05eadf1081a74b2233f291cee2efed25e3a in mainline linux --- sys/dev/pci/drm/amd/pm/amdgpu_dpm.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/dev/pci/drm/amd/pm/amdgpu_dpm.c b/sys/dev/pci/drm/amd/pm/amdgpu_dpm.c index a3c1a66131e..a32d3f58c7b 100644 --- a/sys/dev/pci/drm/amd/pm/amdgpu_dpm.c +++ b/sys/dev/pci/drm/amd/pm/amdgpu_dpm.c @@ -36,6 +36,8 @@ #define amdgpu_dpm_enable_bapm(adev, e) \ ((adev)->powerplay.pp_funcs->enable_bapm((adev)->powerplay.pp_handle, (e))) +#define amdgpu_dpm_is_legacy_dpm(adev) ((adev)->powerplay.pp_handle == (adev)) + int amdgpu_dpm_get_sclk(struct amdgpu_device *adev, bool low) { const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs; @@ -1421,8 +1423,11 @@ int amdgpu_dpm_is_overdrive_supported(struct amdgpu_device *adev) } else { struct pp_hwmgr *hwmgr; - /* SI asic does not carry od_enabled */ - if (adev->family == AMDGPU_FAMILY_SI) + /* + * dpm on some legacy asics don't carry od_enabled member + * as its pp_handle is casted directly from adev. + */ + if (amdgpu_dpm_is_legacy_dpm(adev)) return false; hwmgr = (struct pp_hwmgr *)adev->powerplay.pp_handle; -- 2.20.1