]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/amd/pm: Prevent division by zero
authorDenis Arefev <arefev@swemel.ru>
Fri, 21 Mar 2025 11:08:15 +0000 (14:08 +0300)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 26 Mar 2025 21:41:37 +0000 (17:41 -0400)
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
drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c

index 379012494da57bf00caf7108602ab42fd1aee739..56423aedf3fa7c172b00098597adb716e8df0b5e 100644 (file)
@@ -307,10 +307,10 @@ int vega10_fan_ctrl_set_fan_speed_rpm(struct pp_hwmgr *hwmgr, uint32_t speed)
        int result = 0;
 
        if (hwmgr->thermal_controller.fanInfo.bNoFan ||
-           speed == 0 ||
+           (!speed || speed > UINT_MAX/8) ||
            (speed < hwmgr->thermal_controller.fanInfo.ulMinRPM) ||
            (speed > hwmgr->thermal_controller.fanInfo.ulMaxRPM))
-               return -1;
+               return -EINVAL;
 
        if (PP_CAP(PHM_PlatformCaps_MicrocodeFanControl))
                result = vega10_fan_ctrl_stop_smc_fan_control(hwmgr);