]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: mt76: mt7921: fix potential tx_retries underflow
authorRyder Lee <ryder.lee@mediatek.com>
Fri, 5 Jun 2026 11:33:04 +0000 (04:33 -0700)
committerFelix Fietkau <nbd@nbd.name>
Tue, 9 Jun 2026 10:28:08 +0000 (10:28 +0000)
When FIELD_GET returns 0 for the retry count, subtracting 1 causes
an unsigned integer underflow, resulting in tx_retries becoming a
very large value (0xFFFFFFFF for u32).

Fix by checking if count is non-zero before subtracting 1.

Fixes: 9aecfa754c7f ("wifi: mt76: mt7921e: report tx retries/failed counts in tx free event")
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Link: https://patch.msgid.link/20260605113306.3485554-2-ryder.lee@mediatek.com
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7921/mac.c

index 85434996f8e70bfce05df447b159153d4b5907da..1c2377d0a53d3a38c0b4f7ae9308bac2c49447e9 100644 (file)
@@ -531,8 +531,9 @@ static void mt7921_mac_tx_free(struct mt792x_dev *dev, void *data, int len)
                stat = FIELD_GET(MT_TX_FREE_STATUS, info);
 
                if (wcid) {
-                       wcid->stats.tx_retries +=
-                               FIELD_GET(MT_TX_FREE_COUNT, info) - 1;
+                       u32 count = FIELD_GET(MT_TX_FREE_COUNT, info);
+
+                       wcid->stats.tx_retries += count ? count - 1 : 0;
                        wcid->stats.tx_failed += !!stat;
                }