diff mbox series

[3/4] wifi: mt76: handle possible hardware timeout in mt76x0_phy_tssi_dc_calibrate()

Message ID 20230801050000.18864-3-dmantipov@yandex.ru
State New
Headers show
Series [1/4] wifi: mt76: handle possible error returned by sdio_set_host_pm_flags() | expand

Commit Message

Dmitry Antipov Aug. 1, 2023, 4:57 a.m. UTC
Check for (and hopefully recover from) possible 'mt76_poll_msec()'
timeout in 'mt76x0_phy_tssi_dc_calibrate()' as it's done in
'mt76x0_phy_tssi_adc_calibrate()', convert the subject from 'void'
to return 'int' and 'WARN_ON()' on it in 'mt76x0_phy_calibrate()'.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
index d543ef3de65b..99e4b24e258d 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c
@@ -500,7 +500,7 @@  mt76x0_phy_bbp_set_bw(struct mt76x02_dev *dev, enum nl80211_chan_width width)
 	mt76x02_mcu_function_select(dev, BW_SETTING, bw);
 }
 
-static void mt76x0_phy_tssi_dc_calibrate(struct mt76x02_dev *dev)
+static int mt76x0_phy_tssi_dc_calibrate(struct mt76x02_dev *dev)
 {
 	struct ieee80211_channel *chan = dev->mphy.chandef.chan;
 	u32 val;
@@ -523,7 +523,11 @@  static void mt76x0_phy_tssi_dc_calibrate(struct mt76x02_dev *dev)
 	/* enable TX with DAC0 input */
 	mt76_wr(dev, MT_BBP(TXBE, 6), BIT(31));
 
-	mt76_poll_msec(dev, MT_BBP(CORE, 34), BIT(4), 0, 200);
+	if (!mt76_poll_msec(dev, MT_BBP(CORE, 34), BIT(4), 0, 200)) {
+		mt76_clear(dev, MT_BBP(CORE, 34), BIT(4));
+		return -ETIMEDOUT;
+	}
+
 	dev->cal.tssi_dc = mt76_rr(dev, MT_BBP(CORE, 35)) & 0xff;
 
 	/* stop bypass ADDA */
@@ -537,6 +541,8 @@  static void mt76x0_phy_tssi_dc_calibrate(struct mt76x02_dev *dev)
 
 	if (chan->band == NL80211_BAND_5GHZ)
 		mt76x0_rf_rmw(dev, MT_RF(0, 67), 0xf, 0x4);
+
+	return 0;
 }
 
 static int
@@ -875,7 +881,7 @@  void mt76x0_phy_calibrate(struct mt76x02_dev *dev, bool power_on)
 		if (mt76x0_tssi_enabled(dev)) {
 			mt76_wr(dev, MT_MAC_SYS_CTRL,
 				MT_MAC_SYS_CTRL_ENABLE_RX);
-			mt76x0_phy_tssi_dc_calibrate(dev);
+			WARN_ON(mt76x0_phy_tssi_dc_calibrate(dev) < 0);
 			mt76_wr(dev, MT_MAC_SYS_CTRL,
 				MT_MAC_SYS_CTRL_ENABLE_TX |
 				MT_MAC_SYS_CTRL_ENABLE_RX);