From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2B0446982B for ; Wed, 29 Jul 2026 17:27:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785346052; cv=none; b=RnPuKQtZCEQhgilVR9RaCeP+QZeJ6EfKVY2d2BeyW3VjRSAFDKx91jARkx4NlWlBNvfFwjl11S6PcvZNAkK5pH+WNRPILWiN2LEptKDbcispS/rUjiAPlnJ2Xnt56EIbN11QQZebA8cGUcUW5/d7j4J3MGL+GH4u4kwA6Mom4Qc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785346052; c=relaxed/simple; bh=IlR5SUN+TeNsR1gXMs3dh9kTQqnLR07f654TTJeT4Ak=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=j6kwDz8UrsLrNxCm7wHKbd10LCLliuo/4KQG8ICDO7kgw+qDX4LfPcnr0o1sb0JOxxyn9zISvJT4zXWTJCwlq+h1k9B1BQNCwEenwlq4CNZ+wzJXE8WR5EUYTlH4uNgM4pyXSAMnC+DbxG/HkIb5deT7JWTzTIqv3ffNcxif3iI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ELqKkgbX; arc=none smtp.client-ip=209.85.210.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ELqKkgbX" Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-84e04df8c46so1484828b3a.2 for ; Wed, 29 Jul 2026 10:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785346050; x=1785950850; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=P9wYjqLneOT9CcsqzWwUiSax4MjBMx5743Gw9YabJy4=; b=ELqKkgbXB/sJO8hySozeB0E+NIVZuOZ/n1g399eTxiI9ajwNAWcPHphX5yPk6mIMfc O29E5ym9pp4WLs6L/9IENsaZLzXuEPxbLcKmgK4YS5QHL2zaet/+nViaIZLq0Dlhf5f0 OhhnKZGQZV1FGjNO6j8SxVYeHO8t4anOCvZSceJUB4hd2IBMu6JfxNUK+oWh5wEFiZoS TmUslojUWNg+q6DVJAhDMS4LzIlKMGOG28e4PNA9y0hGvCYGkaoJJ6hGnbO7/P/pujs8 tx2v5RTHoAHl1/K3/EUabDukcoc55ofG+cPpqWL1dPLjPk1ZJH4kSLd/X1jZKt/727a3 7EqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785346050; x=1785950850; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=P9wYjqLneOT9CcsqzWwUiSax4MjBMx5743Gw9YabJy4=; b=K0iQ+52IEHVrHD5x4CXa5jUW5IeN2iwQb25js7QvL8Fy8LERBmDyALzN8un2v+T+Ns vX8DgxC5YZQXG6sf+BxlThJ2mkaqIUg4Wmv+XjTe1De7geeaH3/v7c+0s7BUQKOlkwSB dL1HKMfhkRHHAazkGarGTclfYEuFAOhAfjv23zRr4EXXlSpojKk3HPSH2o0LuZVXCuzY Rw6AClxXUAWthOANjGe8HHLWKn8AgAvrULiBU+3L1UG/8VvIORzoZxRP0bupor9ZwO5w yod8qfK3Fm4T4CQxM08AzwdUobUppKDTWVUwmPiU0ErZ/W9RKWqyiKQxz1s3drRZI/3Q nTzA== X-Forwarded-Encrypted: i=1; AHgh+RoTA7fLZYWkwpxpzQCvmz6iFbPSHlthuuFk405U5BgDGtsdLS8yAFb2p4DV7DSxUTqOcI/DlwU0XrxbVZk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3bFAVaJaeE8qIeLvEyCoKDU9apsJG/bjb99wTKEC4iiSXFK3B akKFeS7ghA/z2dXeL6uqV2gNvyZBTCL4BludKjUL/rucaGG8C9PA0w0S X-Gm-Gg: AR+sD10ptIYFGFBJFVPoZkI+7u9W4mAi4UHHDGKYMnjnqD3YJddxkg6TZtqjnYSrslA jnPKHc7nNFSFt2/xVRrAAW6O6krn5LagZH7m8Hk7XqqS8rrR6sbnuTP0iPK4LP5HcjctKr26aAV PnopiXsoMz9WpHdRkkP3VpY51BvAObOOX+jfNeC12zdhYuY8+MuEbVo9L2gGlg/S14X0v90FF7A hgeovQrULHwl2SrjCN1pxKsY4ueo7hPQ7NshZL5i8jKnQ37cHny6iVwBAO6azP5mvPmxGv0aYyh +IkwHYh3PbdixkMFVi2d8G2NZuKsLS60zQEBMwml+6j8m24ENsa5J/hTgv4Ltvmr1HTGyL4vqvJ 2Bljfgwh934nh885VXAHtozEHofkuBA6amdkqooOiChZAdAhv94OGIlvAJLU7Km4bulJ3zoTDrz 8+A8b6d7iHKHMcIuVqioOLRFdoXnTtotGr/3VjlmdiGW9zdvAbsTTWvWmGZZ8= X-Received: by 2002:a05:6a21:690:b0:3c4:46ca:3339 with SMTP id adf61e73a8af0-3c8ba5d8f94mr8880806637.39.1785346050043; Wed, 29 Jul 2026 10:27:30 -0700 (PDT) Received: from PC.. ([103.172.209.59]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31504d480c5sm19527526eec.25.2026.07.29.10.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jul 2026 10:27:29 -0700 (PDT) From: Mohit Mishra To: Greg Kroah-Hartman Cc: linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Mohit Mishra Subject: [PATCH] staging: rtl8723bs: fix underflow logic in swing index calculations Date: Wed, 29 Jul 2026 22:57:07 +0530 Message-ID: <20260729172707.13333-1-mishraloopmohit@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In ODM_TxPwrTrackSetPwr_8723B(), the baseband swing index variables Final_OFDM_Swing_Index and Final_CCK_Swing_Index are declared as u8. However, their calculation adds Absolute_OFDMSwingIdx, which is a signed 8-bit integer (s8) and can be negative: Final_OFDM_Swing_Index = pDM_Odm->DefaultOfdmIndex + pDM_Odm->Absolute_OFDMSwingIdx[RFPath]; If the resulting sum is negative, it underflows under u8 rules (e.g. -5 becomes 251). This causes the lower-limit checks (e.g. <= 0) to fail, and in MIX_MODE causes the logic to execute the "BBSwing higher than limit" branch instead of capping to 0. Additionally, in BBSWING mode, the check for CCK underflow mistakenly examines the static struct member pDM_Odm->BbSwingIdxCck instead of the newly calculated Final_CCK_Swing_Index: else if (pDM_Odm->BbSwingIdxCck <= 0) Fix this by changing both swing index variable types to int to enable signed math and correct branch selection (aligning with the TODO item to convert remaining unusual variable types). Update the CCK check in BBSWING mode to examine Final_CCK_Swing_Index. Note: The fix is scoped to the calculation and branching logic. When passed downstream to setIqkMatrix_8723B() and setCCKFilterCoefficient(), the values are already clamped within [0, 42], fitting safely in u8. Compile-tested only; no hardware available for testing. Signed-off-by: Mohit Mishra --- drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c b/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c index 6c5f56d5a1f4..4e89847700f3 100644 --- a/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c +++ b/drivers/staging/rtl8723bs/hal/HalPhyRf_8723B.c @@ -160,8 +160,8 @@ void ODM_TxPwrTrackSetPwr_8723B( u8 PwrTrackingLimit_OFDM = 34; /* 0dB */ u8 PwrTrackingLimit_CCK = 28; /* 2dB */ u8 TxRate = 0xFF; - u8 Final_OFDM_Swing_Index = 0; - u8 Final_CCK_Swing_Index = 0; + int Final_OFDM_Swing_Index = 0; + int Final_CCK_Swing_Index = 0; { u16 rate = *(pDM_Odm->pForcedDataRate); @@ -217,7 +217,7 @@ void ODM_TxPwrTrackSetPwr_8723B( if (Final_CCK_Swing_Index >= CCK_TABLE_SIZE) Final_CCK_Swing_Index = CCK_TABLE_SIZE-1; - else if (pDM_Odm->BbSwingIdxCck <= 0) + else if (Final_CCK_Swing_Index <= 0) Final_CCK_Swing_Index = 0; setIqkMatrix_8723B(pDM_Odm, Final_OFDM_Swing_Index, RFPath, -- 2.43.0