Skip to contentSkip to conversation

mt76/mt7915: Fix unsigned compared against zero

PATCH In review John Wood 2 participants 2 messages Jul 4, 2021

Subsystems (5)
lore
Share & tools
lore

John Wood

author
#0 lore raw

PATCH v2 1/1 mt76/mt7915: Fix unsigned compared against zero

The mt7915_dpd_freq_idx() function can return a negative value but this value is assigned to an unsigned variable named idx. Then, the code tests if this variable is less than zero. This can never happen with an unsigned type.

So, change the idx type to a signed one.

Addresses-Coverity-ID: 1484753 ("Unsigned compared against 0")

Fixes 495184ac91bb8 ("mt76: mt7915: add support for applying pre-calibration data")

---
Changelog v1 -> v2
- Add Cc to [email protected]

 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +2 -1
index b3f14ff67c5a..764f25a828fa 100644
@@ -3440,8 +3440,9 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
 {
 	struct mt7915_dev *dev = phy->dev;
 	struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
-	u16 total = 2, idx, center_freq = chandef->center_freq1;
+	u16 total = 2, center_freq = chandef->center_freq1;
 	u8 *cal = dev->cal, *eep = dev->mt76.eeprom.data;
+	int idx;
 
 	if (!(eep[MT_EE_DO_PRE_CAL] & MT_EE_WIFI_CAL_DPD))
 		return 0;

--
2.25.1

maintainer
#1 lore raw
Quoted 33 lines · John Wood

The mt7915_dpd_freq_idx() function can return a negative value but this value is assigned to an unsigned variable named idx. Then, the code tests if this variable is less than zero. This can never happen with an unsigned type.

So, change the idx type to a signed one.

Addresses-Coverity-ID: 1484753 ("Unsigned compared against 0")

Fixes 495184ac91bb8 ("mt76: mt7915: add support for applying pre-calibration data")

---
Changelog v1 -> v2
- Add Cc to [email protected]

 drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +2 -2
index b3f14ff67c5a..764f25a828fa 100644
@@ -3440,8 +3440,9 @@ int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy)
 {
 	struct mt7915_dev *dev = phy->dev;
 	struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
-	u16 total = 2, idx, center_freq = chandef->center_freq1;
+	u16 total = 2, center_freq = chandef->center_freq1;
 	u8 *cal = dev->cal, *eep = dev->mt76.eeprom.data;
+	int idx;
 
 	if (!(eep[MT_EE_DO_PRE_CAL] & MT_EE_WIFI_CAL_DPD))
 		return 0;
--
Quoted 2 lines

2.25.1

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>