Linux-mediatek Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: JB Tsai <jb.tsai@mediatek.com>
To: <nbd@nbd.name>, <lorenzo@kernel.org>
Cc: <linux-wireless@vger.kernel.org>,
	<linux-mediatek@lists.infradead.org>, <Sean.Wang@mediatek.com>,
	<Yung-lun.Chien@mediatek.com>, <jb.tsai@mediatek.com>,
	allen.chien <yung-lun.chien@mediatek.com>
Subject: [PATCH] wifi: mt76: clamp channel power to the s8 range
Date: Wed, 11 Nov 2026 10:27:49 +0800	[thread overview]
Message-ID: <20261111022749.784001-1-jb.tsai@mediatek.com> (raw)

From: "allen.chien" <yung-lun.chien@mediatek.com>

mt76_connac_get_ch_power() computes power as an int from
2 * ch->max_reg_power and then compares it with target_power through
min_t(s8, ...), which truncates the value to 8 bits. An out-of-range
max_reg_power would wrap (e.g. 300 becomes 44) and could lower
target_power wrongly.

Clamp the value into the s8 range when it is calculated. Regulatory
limits are far below that range, so valid input is not affected.

Signed-off-by: allen.chien <yung-lun.chien@mediatek.com>
---
 drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
index ad53bb60d5cd..f5215fa27faf 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
@@ -2168,7 +2168,8 @@ s8 mt76_connac_get_ch_power(struct mt76_phy *phy,
 
 		if (ch->hw_value == chan->hw_value) {
 			if (!(ch->flags & IEEE80211_CHAN_DISABLED)) {
-				int power = 2 * ch->max_reg_power;
+				int power = clamp_t(int, 2 * ch->max_reg_power,
+						    S8_MIN, S8_MAX);
 
 				if (is_mt7663(dev) && (power > 63 || power < -64))
 					power = 63;
-- 
2.45.2



                 reply	other threads:[~2026-11-11  2:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261111022749.784001-1-jb.tsai@mediatek.com \
    --to=jb.tsai@mediatek.com \
    --cc=Sean.Wang@mediatek.com \
    --cc=Yung-lun.Chien@mediatek.com \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=lorenzo@kernel.org \
    --cc=nbd@nbd.name \
    /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