]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/amd/pm/powerplay/hwmgr/smu7_thermal: Prevent division by zero
authorDenis Arefev <arefev@swemel.ru>
Fri, 21 Mar 2025 11:08:16 +0000 (14:08 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 2 May 2025 05:41:03 +0000 (07:41 +0200)
commit 7c246a05df51c52fe0852ce56ba10c41e6ed1f39 upstream.

The user can set any speed value.
If speed is greater than UINT_MAX/8, division by zero is possible.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: c52dcf49195d ("drm/amd/pp: Avoid divide-by-zero in fan_ctrl_set_fan_speed_rpm")
Signed-off-by: Denis Arefev <arefev@swemel.ru>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu7_thermal.c

index 0b30f73649a8384ea7fe0498d1dc2a61db995eff..49f97d6124219c9b5b9e8294a347bc3d51f0d560 100644 (file)
@@ -261,10 +261,10 @@ int smu7_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)
        if (hwmgr->thermal_controller.fanInfo.bNoFan ||
                        (hwmgr->thermal_controller.fanInfo.
                        ucTachometerPulsesPerRevolution == 0) ||
-                       speed == 0 ||
+                       (!speed || speed > UINT_MAX/8) ||
                        (speed < hwmgr->thermal_controller.fanInfo.ulMinRPM) ||
                        (speed > hwmgr->thermal_controller.fanInfo.ulMaxRPM))
-               return 0;
+               return -EINVAL;
 
        if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
                smu7_fan_ctrl_stop_smc_fan_control(hwmgr);