Skip to content

Commit 6ffd02b

Browse files
Nicolas FrattaroliGeorgi Djakov
authored andcommitted
interconnect: mediatek: Aggregate bandwidth with saturating add
By using a regular non-overflow-checking add, the MediaTek icc-emi driver will happy wrap at U32_MAX + 1 to 0. As it's common for the interconnect core to fill in INT_MAX values, this is not a hypothetical situation, but something that actually happens in regular use. This would be pretty disasterous if anything used this driver. Replace the addition with an overflow-checked addition from overflow.h, and saturate to U32_MAX if an overflow is detected. Fixes: b452937 ("interconnect: mediatek: Add MediaTek MT8183/8195 EMI Interconnect driver") Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> Link: https://lore.kernel.org/r/20251124-mt8196-dvfsrc-v2-13-d9c1334db9f3@collabora.com Signed-off-by: Georgi Djakov <djakov@kernel.org>
1 parent 510f821 commit 6ffd02b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/interconnect/mediatek/icc-emi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/module.h>
1313
#include <linux/of.h>
1414
#include <linux/of_platform.h>
15+
#include <linux/overflow.h>
1516
#include <linux/platform_device.h>
1617
#include <linux/soc/mediatek/dvfsrc.h>
1718

@@ -22,7 +23,9 @@ static int mtk_emi_icc_aggregate(struct icc_node *node, u32 tag, u32 avg_bw,
2223
{
2324
struct mtk_icc_node *in = node->data;
2425

25-
*agg_avg += avg_bw;
26+
if (check_add_overflow(*agg_avg, avg_bw, agg_avg))
27+
*agg_avg = U32_MAX;
28+
2629
*agg_peak = max_t(u32, *agg_peak, peak_bw);
2730

2831
in->sum_avg = *agg_avg;

0 commit comments

Comments
 (0)