drm/amd/pm: avoid potential UBSAN issue on legacy asics
authorjsg <jsg@openbsd.org>
Tue, 13 Jun 2023 03:29:00 +0000 (03:29 +0000)
committerjsg <jsg@openbsd.org>
Tue, 13 Jun 2023 03:29:00 +0000 (03:29 +0000)
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

index a3c1a66..a32d3f5 100644 (file)
@@ -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;