]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/amd/display: fix initial backlight brightness calculation
authorLauri Tirkkonen <lauri@hacktheplanet.fi>
Mon, 21 Jul 2025 00:59:40 +0000 (09:59 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:34:31 +0000 (16:34 +0200)
commit 9c2883057b3c861879b647f34e8bc448954e8729 upstream.

DIV_ROUND_CLOSEST(x, 100) returns either 0 or 1 if 0<x<=100, so the
division needs to be performed after the multiplication and not the
other way around, to properly scale the value.

Fixes: 8b5f3a229a70 ("drm/amd/display: Fix default DC and AC levels")
Signed-off-by: Lauri Tirkkonen <lauri@hacktheplanet.fi>
Cc: stable@vger.kernel.org
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://lore.kernel.org/r/aH2Q_HJvxKbW74vU@hacktheplanet.fi
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

index 7b5440bdad2f35a4df278c8348e59eb893bc19a3..57d86ebe1871ca089fa0b7a5992aa135428f46d7 100644 (file)
@@ -4952,9 +4952,9 @@ amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)
        caps = &dm->backlight_caps[aconnector->bl_idx];
        if (get_brightness_range(caps, &min, &max)) {
                if (power_supply_is_system_supplied() > 0)
-                       props.brightness = (max - min) * DIV_ROUND_CLOSEST(caps->ac_level, 100);
+                       props.brightness = DIV_ROUND_CLOSEST((max - min) * caps->ac_level, 100);
                else
-                       props.brightness = (max - min) * DIV_ROUND_CLOSEST(caps->dc_level, 100);
+                       props.brightness = DIV_ROUND_CLOSEST((max - min) * caps->dc_level, 100);
                /* min is zero, so max needs to be adjusted */
                props.max_brightness = max - min;
                drm_dbg(drm, "Backlight caps: min: %d, max: %d, ac %d, dc %d\n", min, max,