PM / devfreq: tegra30: Fix integer overflow on CPU's freq max out
authorDmitry Osipenko <digetx@gmail.com>
Mon, 4 Nov 2019 21:56:03 +0000 (00:56 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 1 Oct 2020 18:40:02 +0000 (20:40 +0200)
[ Upstream commit 53b4b2aeee26f42cde5ff2a16dd0d8590c51a55a ]

There is another kHz-conversion bug in the code, resulting in integer
overflow. Although, this time the resulting value is 4294966296 and it's
close to ULONG_MAX, which is okay in this case.

Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com>
Tested-by: Peter Geis <pgwipeout@gmail.com>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/devfreq/tegra-devfreq.c

index fe9dce0245bf0c7d32b2c8eb3590e7f73651ae6d..a20267d93f8a4ba8e2e4ad4cfeb58ef64cc84eb2 100644 (file)
@@ -79,6 +79,8 @@
 
 #define KHZ                                                    1000
 
+#define KHZ_MAX                                                (ULONG_MAX / KHZ)
+
 /* Assume that the bus is saturated if the utilization is 25% */
 #define BUS_SATURATION_RATIO                                   25
 
@@ -179,7 +181,7 @@ struct tegra_actmon_emc_ratio {
 };
 
 static struct tegra_actmon_emc_ratio actmon_emc_ratios[] = {
-       { 1400000, ULONG_MAX },
+       { 1400000,    KHZ_MAX },
        { 1200000,    750000 },
        { 1100000,    600000 },
        { 1000000,    500000 },