drm/amd/display: Validate backlight caps are sane
authorjsg <jsg@openbsd.org>
Mon, 7 Oct 2024 05:30:12 +0000 (05:30 +0000)
committerjsg <jsg@openbsd.org>
Mon, 7 Oct 2024 05:30:12 +0000 (05:30 +0000)
From Mario Limonciello
c886061bbdd1f37190939b11926055413e86a56c in linux-6.6.y/6.6.54
327e62f47eb57ae5ff63de82b0815557104e439a in mainline linux

sys/dev/pci/drm/amd/display/amdgpu_dm/amdgpu_dm.c

index 9688dc5..a74f6e9 100644 (file)
@@ -4041,6 +4041,7 @@ static int amdgpu_dm_mode_config_init(struct amdgpu_device *adev)
 
 #define AMDGPU_DM_DEFAULT_MIN_BACKLIGHT 12
 #define AMDGPU_DM_DEFAULT_MAX_BACKLIGHT 255
+#define AMDGPU_DM_MIN_SPREAD ((AMDGPU_DM_DEFAULT_MAX_BACKLIGHT - AMDGPU_DM_DEFAULT_MIN_BACKLIGHT) / 2)
 #define AUX_BL_DEFAULT_TRANSITION_TIME_MS 50
 
 static void amdgpu_dm_update_backlight_caps(struct amdgpu_display_manager *dm,
@@ -4055,6 +4056,21 @@ static void amdgpu_dm_update_backlight_caps(struct amdgpu_display_manager *dm,
                return;
 
        amdgpu_acpi_get_backlight_caps(&caps);
+
+       /* validate the firmware value is sane */
+       if (caps.caps_valid) {
+               int spread = caps.max_input_signal - caps.min_input_signal;
+
+               if (caps.max_input_signal > AMDGPU_DM_DEFAULT_MAX_BACKLIGHT ||
+                   caps.min_input_signal < AMDGPU_DM_DEFAULT_MIN_BACKLIGHT ||
+                   spread > AMDGPU_DM_DEFAULT_MAX_BACKLIGHT ||
+                   spread < AMDGPU_DM_MIN_SPREAD) {
+                       DRM_DEBUG_KMS("DM: Invalid backlight caps: min=%d, max=%d\n",
+                                     caps.min_input_signal, caps.max_input_signal);
+                       caps.caps_valid = false;
+               }
+       }
+
        if (caps.caps_valid) {
                dm->backlight_caps[bl_idx].caps_valid = true;
                if (caps.aux_support)