From bd1526b7424a4af6cc433ce1d396b22d1960664c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 22:52:20 +0000 Subject: [PATCH 1/5] mt76x02: fix sign_extend() sign inversion logic The mt76x02_sign_extend() function uses sign-magnitude encoding where bit[size-1] is the sign bit and the lower bits are the magnitude. The return statement had the sign condition inverted: 'sign ? val : -val' returned a positive value when the sign bit was set (indicating a negative number) and vice versa. Fix this by swapping the return expressions to 'sign ? -val : val', so that a set sign bit correctly yields a negative result. This bug affected RSSI offsets, LNA gain calibration, TX power delta values, and other calibration parameters read from EEPROM. --- mt76x02_eeprom.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mt76x02_eeprom.h b/mt76x02_eeprom.h index 13fa708..4c328ff 100644 --- a/mt76x02_eeprom.h +++ b/mt76x02_eeprom.h @@ -140,7 +140,7 @@ mt76x02_sign_extend(u32 val, unsigned int size) val &= BIT(size - 1) - 1; - return sign ? val : -val; + return sign ? -val : val; } static inline int From b2815bd010ca3972d9b543ab6241e1d18cb5a320 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 22:52:35 +0000 Subject: [PATCH 2/5] mt76x02: use ARRAY_SIZE() instead of sizeof() for rate power iteration The rate power table iteration loops used sizeof(r->all) to determine the iteration count. This works by coincidence because the element type is s8 (1 byte), making sizeof equal to the element count. Use ARRAY_SIZE(r->all) instead, which explicitly expresses the intent of iterating over all elements and avoids a silent dependency on the element size. --- mt76x02_phy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mt76x02_phy.c b/mt76x02_phy.c index f98ba3d..d1f7aee 100644 --- a/mt76x02_phy.c +++ b/mt76x02_phy.c @@ -64,7 +64,7 @@ int mt76x02_get_max_rate_power(struct mt76x02_rate_power *r) s8 ret = 0; int i; - for (i = 0; i < sizeof(r->all); i++) + for (i = 0; i < ARRAY_SIZE(r->all); i++) ret = max(ret, r->all[i]); return ret; @@ -75,7 +75,7 @@ void mt76x02_limit_rate_power(struct mt76x02_rate_power *r, int limit) { int i; - for (i = 0; i < sizeof(r->all); i++) + for (i = 0; i < ARRAY_SIZE(r->all); i++) if (r->all[i] > limit) r->all[i] = limit; } @@ -85,7 +85,7 @@ void mt76x02_add_rate_power_offset(struct mt76x02_rate_power *r, int offset) { int i; - for (i = 0; i < sizeof(r->all); i++) + for (i = 0; i < ARRAY_SIZE(r->all); i++) r->all[i] += offset; } EXPORT_SYMBOL_GPL(mt76x02_add_rate_power_offset); From a56481da5593efd0d972d6870e2e877113ea033d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 22:53:56 +0000 Subject: [PATCH 3/5] mt76x02: fix watchdog reset retry count and coding style issues Three coding style/correctness issues are fixed: 1. mt76x02_mmio.c: dma_is_busy() used 4-space indentation instead of tabs for the return statement, inconsistent with the rest of the file. 2. mt76x02_mmio.c: The DMA busy wait loop used '--retry != 0' which only performs 4 iterations despite retry being initialized to 5. Use 'retry-- > 0' to perform the intended 5 iterations. 3. mt76x02_txrx.c: Missing space between the '=' operator and 'dev->' in three assignment statements. --- mt76x02_mmio.c | 7 ++++--- mt76x02_txrx.c | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mt76x02_mmio.c b/mt76x02_mmio.c index 68d80b7..984928e 100644 --- a/mt76x02_mmio.c +++ b/mt76x02_mmio.c @@ -461,8 +461,9 @@ static void mt76x02_reset_state(struct mt76x02_dev *dev) static bool dma_is_busy(struct mt76x02_dev *dev) { u32 dma_status = mt76_rr(dev, MT_WPDMA_GLO_CFG); - return dma_status & (MT_WPDMA_GLO_CFG_TX_DMA_EN | - MT_WPDMA_GLO_CFG_RX_DMA_EN); + + return dma_status & (MT_WPDMA_GLO_CFG_TX_DMA_EN | + MT_WPDMA_GLO_CFG_RX_DMA_EN); } static void mt76x02_watchdog_reset(struct mt76x02_dev *dev) @@ -519,7 +520,7 @@ static void mt76x02_watchdog_reset(struct mt76x02_dev *dev) if (restart) { int retry = 5; - while (--retry != 0 && dma_is_busy(dev)) { + while (retry-- > 0 && dma_is_busy(dev)) { usleep_range(5000, 10000); } mt76_mcu_restart(dev); diff --git a/mt76x02_txrx.c b/mt76x02_txrx.c index 913b5f6..f28fb32 100644 --- a/mt76x02_txrx.c +++ b/mt76x02_txrx.c @@ -68,10 +68,10 @@ s8 mt76x02_tx_get_max_txpwr_adj(struct mt76x02_dev *dev, nss = ieee80211_rate_get_vht_nss(rate); idx = ((nss - 1) << 3) + mcs; - max_txpwr =dev->rate_power.ht[idx & 0xf]; + max_txpwr = dev->rate_power.ht[idx & 0xf]; } } else if (rate->flags & IEEE80211_TX_RC_MCS) { - max_txpwr =dev->rate_power.ht[rate->idx & 0xf]; + max_txpwr = dev->rate_power.ht[rate->idx & 0xf]; } else { enum nl80211_band band = dev->mphy.chandef.chan->band; @@ -86,7 +86,7 @@ s8 mt76x02_tx_get_max_txpwr_adj(struct mt76x02_dev *dev, else max_txpwr = rp->ofdm[r->hw_value & 0x7]; } else { - max_txpwr =dev->rate_power.ofdm[rate->idx & 0x7]; + max_txpwr = dev->rate_power.ofdm[rate->idx & 0x7]; } } From b4b15bc82b09d74b99ce9d5b7c69d7e5ae8ce6f4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 22:54:05 +0000 Subject: [PATCH 4/5] mt76x02: return -EINVAL instead of -1 in eeprom_copy() The mt76x02_eeprom_copy() function returned -1 on error instead of a proper Linux error code. Use -EINVAL to follow the standard kernel convention for invalid argument errors, as this error indicates the requested EEPROM field range exceeds the available EEPROM size. --- mt76x02_eeprom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mt76x02_eeprom.c b/mt76x02_eeprom.c index c0227b2..76e7edc 100644 --- a/mt76x02_eeprom.c +++ b/mt76x02_eeprom.c @@ -47,7 +47,7 @@ int mt76x02_eeprom_copy(struct mt76x02_dev *dev, void *dest, int len) { if (field + len > dev->mt76.eeprom.size) - return -1; + return -EINVAL; memcpy(dest, dev->mt76.eeprom.data + field, len); return 0; From 1f3dcd4a4d70c27b6ce7fb35af4e503927f51fa8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Mar 2026 22:54:25 +0000 Subject: [PATCH 5/5] mt7603: fix coding style in wtbl_set_smps() The do-while loop in mt7603_wtbl_set_smps() had the opening brace on a separate line from the 'do' keyword, and the mt76_poll() call had excessive indentation for its continuation argument. Fix both issues to match the Linux kernel coding style. --- mt7603/mac.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mt7603/mac.c b/mt7603/mac.c index b731f24..e1f9810 100644 --- a/mt7603/mac.c +++ b/mt7603/mac.c @@ -234,11 +234,10 @@ void mt7603_wtbl_set_smps(struct mt7603_dev *dev, struct mt7603_sta *sta, return; num_retries = 3; - do - { + do { mt76_rmw_field(dev, addr, MT_WTBL1_W2_SMPS, enabled); successful = mt76_poll(dev, addr, MT_WTBL1_W2_SMPS, - enabled, 15000); + enabled, 15000); } while (!successful && --num_retries); if (successful)