]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd/pm: Prevent division by zero
authorDenis Arefev <arefev@swemel.ru>
Fri, 21 Mar 2025 10:52:32 +0000 (13:52 +0300)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 26 Mar 2025 21:41:23 +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: b64625a303de ("drm/amd/pm: correct the address of Arcturus fan related registers")
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/swsmu/smu11/arcturus_ppt.c

index 8aa61a9f77782be34e405e94d31948790ed1bb24..453952cdc353b1a4e4f94e41b12c9e8b774d828a 100644 (file)
@@ -1267,6 +1267,9 @@ static int arcturus_set_fan_speed_rpm(struct smu_context *smu,
        uint32_t crystal_clock_freq = 2500;
        uint32_t tach_period;
 
+       if (!speed || speed > UINT_MAX/8)
+               return -EINVAL;
+
        tach_period = 60 * crystal_clock_freq * 10000 / (8 * speed);
        WREG32_SOC15(THM, 0, mmCG_TACH_CTRL_ARCT,
                     REG_SET_FIELD(RREG32_SOC15(THM, 0, mmCG_TACH_CTRL_ARCT),