From 66d00b8c9dac08e46558d84d54ee7f245bcffce8 Mon Sep 17 00:00:00 2001 From: Lorenzo Bianconi Date: Mon, 6 Apr 2020 23:56:30 +0200 Subject: [PATCH] mt76: mt7615: fix possible division by 0 in mt7615_mac_update_mib_stats Check that val is not zero before aggr_per estimation in order to avoid a possible division by 0 Signed-off-by: Lorenzo Bianconi Signed-off-by: Felix Fietkau --- mt7615/mac.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mt7615/mac.c b/mt7615/mac.c index ed6eb19f..1ef98888 100644 --- a/mt7615/mac.c +++ b/mt7615/mac.c @@ -1773,9 +1773,11 @@ mt7615_mac_update_mib_stats(struct mt7615_phy *phy) val = mt76_get_field(dev, MT_MIB_SDR14(ext_phy), MT_MIB_AMPDU_MPDU_COUNT); - val2 = mt76_get_field(dev, MT_MIB_SDR15(ext_phy), - MT_MIB_AMPDU_ACK_COUNT); - mib->aggr_per = 1000 * (val - val2) / val; + if (val) { + val2 = mt76_get_field(dev, MT_MIB_SDR15(ext_phy), + MT_MIB_AMPDU_ACK_COUNT); + mib->aggr_per = 1000 * (val - val2) / val; + } aggr = ext_phy ? ARRAY_SIZE(dev->mt76.aggr_stats) / 2 : 0; for (i = 0; i < 4; i++) {