]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: mt76: mt7996: fix overflows seen when writing limit attributes
authorxueqin Luo <luoxueqin@kylinos.cn>
Mon, 2 Dec 2024 03:19:16 +0000 (11:19 +0800)
committerFelix Fietkau <nbd@nbd.name>
Tue, 14 Jan 2025 12:34:34 +0000 (13:34 +0100)
DIV_ROUND_CLOSEST() after kstrtoul() results in an overflow if a large
number such as 18446744073709551615 is provided by the user.
Fix it by reordering clamp_val() and DIV_ROUND_CLOSEST() operations.
This commit was inspired by commit: 57ee12b6c514.

Fixes: 6879b2e94172 ("wifi: mt76: mt7996: add thermal sensor device support")
Signed-off-by: xueqin Luo <luoxueqin@kylinos.cn>
Link: https://patch.msgid.link/20241202031917.23741-2-luoxueqin@kylinos.cn
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7996/init.c

index 2d36c73251378a221e04c0730a922e91075958b8..8cfb122b48accd991301fd510c9d2d0a20e43b88 100644 (file)
@@ -82,7 +82,7 @@ static ssize_t mt7996_thermal_temp_store(struct device *dev,
                return ret;
 
        mutex_lock(&phy->dev->mt76.mutex);
-       val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), 40, 130);
+       val = DIV_ROUND_CLOSEST(clamp_val(val, 40 * 1000, 130 * 1000), 1000);
 
        /* add a safety margin ~10 */
        if ((i - 1 == MT7996_CRIT_TEMP_IDX &&