mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: sunliming <sunliming@kylinos.cn>,
	kernel test robot <lkp@intel.com>,
	Dan Carpenter <error27@gmail.com>, Felix Fietkau <nbd@nbd.name>,
	Sasha Levin <sashal@kernel.org>,
	matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com,
	lorenzo@kernel.org, shayne.chen@mediatek.com,
	chui-hao.chiu@mediatek.com, Bo.Jiao@mediatek.com,
	qasdev00@gmail.com, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: [PATCH AUTOSEL 6.15 015/118] wifi: mt76: mt7996: fix uninitialized symbol warning
Date: Tue,  3 Jun 2025 20:49:06 -0400	[thread overview]
Message-ID: <20250604005049.4147522-15-sashal@kernel.org> (raw)
In-Reply-To: <20250604005049.4147522-1-sashal@kernel.org>

From: sunliming <sunliming@kylinos.cn>

[ Upstream commit 187de25110c8ac8d52e24f8c596ebdcbcd55bbbf ]

Fix below smatch warnings:
drivers/net/wireless/mediatek/mt76/mt7996/main.c:952 mt7996_mac_sta_add_links()
error: uninitialized symbol 'err'.
drivers/net/wireless/mediatek/mt76/mt7996/main.c:1133 mt7996_set_rts_threshold()
error: uninitialized symbol 'ret'.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/r/202504101051.1ya4Z4va-lkp@intel.com/
Signed-off-by: sunliming <sunliming@kylinos.cn>
Link: https://patch.msgid.link/20250419031528.2073892-1-sunliming@linux.dev
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

This repository appears to be much older or a different branch. Let me
analyze the commit based on the code changes alone: **Analysis of the
commit:** ## YES **Extensive explanation:** This commit should be
backported to stable kernel trees for the following reasons: ### 1.
**Bug Type: Uninitialized Variable Bug** The commit fixes uninitialized
variable warnings detected by static analysis tools (smatch). Looking at
the changes: - In `mt7996_mac_sta_add_links()`: The variable `err` was
declared but not initialized (`int err;`) and changed to `int err = 0;`
- In `mt7996_set_rts_threshold()`: The variable `ret` was declared but
not initialized (`int i, ret;`) and changed to `int i, ret = 0;` ### 2.
**Consistent with Similar Backported Commits** This fix is very similar
to the reference commits that were marked as "Backport Status: YES": -
**Similar Commit #1**: Fixed uninitialized variable `msta` in mt7915
driver - marked YES for backport - **Similar Commit #3**: Fixed
uninitialized variable `ret` in ath12k driver - marked YES for backport
- **Similar Commit #4**: Fixed uninitialized variable `msta` in mt7921
driver - marked YES for backport All these commits follow the same
pattern: initializing variables to prevent potential undefined behavior.
### 3. **Analysis of Code Paths** Looking at the specific functions:
**mt7996_mac_sta_add_links():** - The `err` variable could potentially
be returned uninitialized if the `for_each_set_bit` loop doesn't execute
any iterations (if `new_links` is 0) - While this might be rare in
practice, returning an uninitialized value could lead to unpredictable
behavior **mt7996_set_rts_threshold():** - The `ret` variable could be
returned uninitialized if `hw->wiphy->n_radio` is 0, causing the for
loop to not execute - Again, this creates undefined behavior where the
function might return garbage values ### 4. **Stable Tree Criteria
Compliance** This commit meets the stable tree criteria: - **Important
bugfix**: Yes - fixes potential undefined behavior - **Small and
contained**: Yes - only two simple variable initializations - **No
architectural changes**: Yes - minimal change that doesn't affect design
- **Low regression risk**: Yes - initialization to 0 is safe and
expected - **Clear side effects**: No side effects beyond fixing the bug
### 5. **Driver Context** The mt7996 driver is for MediaTek Wi-Fi 7
devices, which are actively used hardware. Uninitialized variable bugs
in wireless drivers can potentially cause: - Random return values
leading to unpredictable error handling - Possible crashes or unexpected
behavior in error paths - Static analysis tool warnings that indicate
potential runtime issues ### 6. **Static Analysis Detection** The fact
that this was caught by automated static analysis tools (smatch) and
reported by the kernel test robot indicates this is a legitimate concern
that should be addressed in stable kernels. The fix is identical in
nature to multiple other WiFi driver commits that have been successfully
backported, demonstrating this is a well-established pattern for stable
tree inclusion.

 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7996/main.c b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
index 91c64e3a0860f..ba8cfca842d0f 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7996/main.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -987,7 +987,7 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 {
 	struct mt7996_sta *msta = (struct mt7996_sta *)sta->drv_priv;
 	unsigned int link_id;
-	int err;
+	int err = 0;
 
 	for_each_set_bit(link_id, &new_links, IEEE80211_MLD_MAX_NUM_LINKS) {
 		struct ieee80211_bss_conf *link_conf;
@@ -1244,7 +1244,7 @@ static void mt7996_tx(struct ieee80211_hw *hw,
 static int mt7996_set_rts_threshold(struct ieee80211_hw *hw, u32 val)
 {
 	struct mt7996_dev *dev = mt7996_hw_dev(hw);
-	int i, ret;
+	int i, ret = 0;
 
 	mutex_lock(&dev->mt76.mutex);
 
-- 
2.39.5


  parent reply	other threads:[~2025-06-04  0:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250604005049.4147522-1-sashal@kernel.org>
2025-06-04  0:48 ` [PATCH AUTOSEL 6.15 008/118] wifi: mt76: mt7996: drop fragments with multicast or broadcast RA Sasha Levin
2025-06-04  0:49 ` [PATCH AUTOSEL 6.15 010/118] Bluetooth: btusb: Add new VID/PID 13d3/3630 for MT7925 Sasha Levin
2025-06-04  0:49 ` [PATCH AUTOSEL 6.15 014/118] Bluetooth: btmtksdio: Fix wakeup source leaks on device unbind Sasha Levin
2025-06-04  0:49 ` Sasha Levin [this message]
2025-06-04  0:49 ` [PATCH AUTOSEL 6.15 016/118] wifi: mt76: mt76x2: Add support for LiteOn WN4516R,WN4519R Sasha Levin
2025-06-04  0:49 ` [PATCH AUTOSEL 6.15 017/118] wifi: mt76: mt7921: add 160 MHz AP for mt7922 device Sasha Levin
2025-06-04  0:49 ` [PATCH AUTOSEL 6.15 018/118] wifi: mt76: mt7925: introduce thermal protection Sasha Levin
2025-06-04  0:49 ` [PATCH AUTOSEL 6.15 029/118] net: phy: mediatek: do not require syscon compatible for pio property Sasha Levin
2025-06-04  0:50 ` [PATCH AUTOSEL 6.15 070/118] tracing: Only return an adjusted address if it matches the kernel address Sasha Levin
2025-06-04  1:15   ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250604005049.4147522-15-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=Bo.Jiao@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chui-hao.chiu@mediatek.com \
    --cc=error27@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=lkp@intel.com \
    --cc=lorenzo@kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nbd@nbd.name \
    --cc=patches@lists.linux.dev \
    --cc=qasdev00@gmail.com \
    --cc=shayne.chen@mediatek.com \
    --cc=stable@vger.kernel.org \
    --cc=sunliming@kylinos.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®