All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Liao Yuanhong <liaoyuanhong@vivo.com>,
	Johannes Berg <johannes.berg@intel.com>,
	Sasha Levin <sashal@kernel.org>,
	johannes@sipsolutions.net, linux-wireless@vger.kernel.org
Subject: [PATCH AUTOSEL 6.16-5.4] wifi: mac80211: fix incorrect type for ret
Date: Mon,  8 Sep 2025 20:30:12 -0400	[thread overview]
Message-ID: <20250909003025.2493540-2-sashal@kernel.org> (raw)
In-Reply-To: <20250909003025.2493540-1-sashal@kernel.org>

From: Liao Yuanhong <liaoyuanhong@vivo.com>

[ Upstream commit a33b375ab5b3a9897a0ab76be8258d9f6b748628 ]

The variable ret is declared as a u32 type, but it is assigned a value
of -EOPNOTSUPP. Since unsigned types cannot correctly represent negative
values, the type of ret should be changed to int.

Signed-off-by: Liao Yuanhong <liaoyuanhong@vivo.com>
Link: https://patch.msgid.link/20250825022911.139377-1-liaoyuanhong@vivo.com
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

**Backport Status: YES**

This commit should be backported to stable kernel trees for the
following reasons:

## Analysis of the Code Change

The commit fixes a clear type mismatch bug in `net/mac80211/driver-
ops.h:1419` where `ret` was incorrectly declared as `u32` while being
assigned the negative error value `-EOPNOTSUPP` (-95):

```c
// Before (incorrect):
u32 ret = -EOPNOTSUPP;  // Assigns -95 to unsigned, becomes 4294967201

// After (correct):
int ret = -EOPNOTSUPP;  // Properly represents -95
```

## Why This Qualifies for Stable Backport

1. **Bug Fix**: This is a genuine bug that violates C type safety.
   Assigning negative values to unsigned types is incorrect and can lead
   to undefined behavior or compiler-specific interpretations.

2. **Long-standing Issue**: The bug has existed since kernel v4.20
   (commit bc847970f43281cb, October 2018), affecting all stable kernels
   from 4.20 onwards. A 7-year-old bug deserves fixing in stable trees.

3. **Minimal and Contained**: The fix is a single-line type change from
   `u32` to `int`. It's about as minimal and low-risk as a kernel patch
   can be.

4. **No Functional Changes**: The fix doesn't introduce new features or
   change architecture - it simply corrects a type declaration to match
   its intended use.

5. **Correctness Over Impact**: While the practical impact was minimal
   due to implicit type conversion preserving the negative value when
   returned as `int`, this is still incorrect code that:
   - Violates type safety principles
   - Can trigger compiler warnings
   - Sets a bad example for similar code patterns
   - Could break with different compiler optimizations or architectures

6. **Affects Error Handling Path**: The bug is in error handling code
   (`-EOPNOTSUPP`), and correct error handling is critical for kernel
   stability. Even if the current behavior happens to work, relying on
   implicit conversions for error codes is dangerous.

7. **Simple Verification**: The fix is trivially verifiable - the
   function returns `int` and all error codes are negative, so `ret`
   should be `int`, not `u32`.

## Stable Tree Rules Compliance

The commit perfectly aligns with stable kernel rules:
- ✅ Fixes a real bug (type mismatch)
- ✅ Already merged in Linus' tree
- ✅ Minimal size (1 line change)
- ✅ No new features added
- ✅ Low regression risk
- ✅ Improves code correctness

The fact that this bug existed for 7 years without causing reported
failures actually strengthens the case for backporting - it means the
fix is extremely safe while still correcting incorrect code that could
potentially cause issues with different compilers or architectures.

 net/mac80211/driver-ops.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h
index 307587c8a0037..7964a7c5f0b2b 100644
--- a/net/mac80211/driver-ops.h
+++ b/net/mac80211/driver-ops.h
@@ -1389,7 +1389,7 @@ drv_get_ftm_responder_stats(struct ieee80211_local *local,
 			    struct ieee80211_sub_if_data *sdata,
 			    struct cfg80211_ftm_responder_stats *ftm_stats)
 {
-	u32 ret = -EOPNOTSUPP;
+	int ret = -EOPNOTSUPP;
 
 	might_sleep();
 	lockdep_assert_wiphy(local->hw.wiphy);
-- 
2.51.0


  reply	other threads:[~2025-09-09  0:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09  0:30 [PATCH AUTOSEL 6.16-6.1] wifi: mac80211: increase scan_ies_len for S1G Sasha Levin
2025-09-09  0:30 ` Sasha Levin [this message]
2025-09-09  0:30 ` [PATCH AUTOSEL 6.16-6.12] nvme: fix PI insert on write Sasha Levin
2025-09-09  0:30 ` [PATCH AUTOSEL 6.16-5.4] pcmcia: omap_cf: Mark driver struct with __refdata to prevent section mismatch Sasha Levin
2025-09-09  0:30 ` [PATCH AUTOSEL 6.16-5.4] ALSA: firewire-motu: drop EPOLLOUT from poll return values as write is not supported Sasha Levin
2025-09-09  0:30 ` [PATCH AUTOSEL 6.16] wifi: mt76: do not add non-sta wcid entries to the poll list Sasha Levin
2025-09-09  0:30 ` [PATCH AUTOSEL 6.16-6.6] wifi: wilc1000: avoid buffer overflow in WID string configuration Sasha Levin

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=20250909003025.2493540-2-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=johannes.berg@intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=liaoyuanhong@vivo.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.