From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (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 15EC73BF66C for ; Thu, 30 Jul 2026 09:45:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785404760; cv=none; b=LCGxCMgToD2sZ10BOpgnkmFqu+8eu9PgJdgJv4XZkQ7vAJXSIEEyO4dsGHdu6A0qOPUqcaZQJT1lnjGxQlEAdImamYLfNjKncmWtfjxMIQ4DD0jOg6+jDDVsf/VHJMY5M8Q3z/n0kzkDU4TJ6fUweTrc6HDeacBKOG2ho/buW7U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785404760; c=relaxed/simple; bh=FEbxtOCMm+1zTlknwYYR45DhD/+98s/zCd3MSrKtwJg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pmErY8wABcDISp6ZLcCy3Eyt1qLuZHGSJPROkJPT3niT3Hi/saxMbv4bp97x7nn6M+0T/hi+nz7dNP8KL1u7fSgMHW2uhjeuFFVQIT+ovz011HOhWrJ1nc3+Jb1yjjKGJQE/4vlzx8omOP0e1uloLjZp1Vc8cBz100wpVnXRNDQ= 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=TWxmczT9; arc=none smtp.client-ip=209.85.208.172 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="TWxmczT9" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-39c8ee87f7eso16269861fa.3 for ; Thu, 30 Jul 2026 02:45:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785404757; x=1786009557; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=mWDRAM6ScA6tepJC1oPzWjfjIMkzBdpkHj1B47+vimc=; b=TWxmczT926ob0HZzIrUbQ8ab2pUKhmZpXAAzrYfPWqWfZDjnhcdv/x2/4X3rC/vAfC FyCG+2wX+cy12R9fJQJqIvDRq8uOwfXivugiiGOTMox/dgi1geueyQ2CqzUMw2CrLfK+ FQx7SPNR3S0aERKXuHiRh8Wlre06a3+lCc18TsW0QcNihXhDV8y2f0uRQtZ4g6JvzdkL I8z49+C79ZmONCC9oZFQqCQQB1x2wx4OueZUyGtDIH2qcAo5eQ23gKMAa2x2WBaGtoR3 NO6zUVkmJ9EokECo2YjEHRT/WST3hxL+ozLliXfYyaVLocOoCcEG1GspV+o3jJkeg79W jBjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785404757; x=1786009557; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=mWDRAM6ScA6tepJC1oPzWjfjIMkzBdpkHj1B47+vimc=; b=eXQLqfhNdBN4n6YXCA3jFV/U3exUZtoCoteD1ypGj1pK11pBJY7n6HICA2hz5h1jE1 K3SPeo2WGe4p8N1Xu4HnQd6FE2J5NjaCs4sU7YJEs0+hXTYNz1Q+f3929PKDiPweXW1D NhPKtebJrb5+aIf6WtDKoUY4vftGSHoe45p16LEiENtLgfQ7MMYxDpF+Q7ONepQU4B2h l6vxWGNA+imJa5f81Nsd5ZFedisJkreaEoP+FDFkC0egolWcfnk2mohbw5696PCLxtD4 vG5OnGA24ccQNVqpnwy6Q0TlFpeDu51d+g3iUxmI7Kr+TLMEGLJiIHoWrPMf7yEBnX3W Wh9Q== X-Forwarded-Encrypted: i=1; AHgh+Rrki0Q4a+UngT2Hh6VWV4mADL8eS26Rq7YdF1ybaGXZ5G9mECMhDQ00UURhVPbLVSIVk1jKVPGAwLYM22k=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6ScTRbMnHrcdVw/derd539mdgi5KqMVf90RX/aM99EENjbJqS jPgXGeqd4L/O7VzprGBo9unIQWcDj0RG4UpeW3vLukF5a6ty5NqrLApF X-Gm-Gg: AR+sD12lwWW7EaoHahh8PGMVvTFYIe6dYQwbv1N08Q91O3p2MIEgTrVCSJfD335Pftu 9i79UpZjNSTrmhNYm5+srsM7NpM21M6JF4ifLPZpGsPLPLQivA9Y4VU5Qhx3nhHz1Zi4+BwkIHa D5ckCB1Wtrliq5XtJcrj9oGs5urS1WZLy8DXsLPODgOv2oUrkxS+3RFsL+aqAFQh9DjHl2zlnwi rrqO5Iusq44OU1rt5Gtt4lA/FWWlDjQb6LC6HbH8qFev+Ayrn3G+VlL3JxQFikvSblfZB04bDN1 rwlPU15jRoBXzsF7UTDie4MqO7QYgf0SMGBVnj7V+9bt7vDMV0XQOoyBRipyNwGKeD1Sj5UX+dC xqFL5b7Sqb3yLkwDGFVmj6xzryuaakC5s5OrzVmuo9G6aUqVlPNzYHM65qg0PuC0CUOkKKeJ5SR j42ARsYyNCrzy4hZUDfGz7JUVDAF+Df8WyMHj/uKErB8loUfMnEBS4RnnOfM8= X-Received: by 2002:a05:6512:350c:b0:5b2:9c0e:a2d9 with SMTP id 2adb3069b0e04-5b2db3916a4mr379748e87.65.1785404756912; Thu, 30 Jul 2026 02:45:56 -0700 (PDT) Received: from archlinux ([94.229.19.199]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5b2db942d75sm226698e87.3.2026.07.30.02.45.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2026 02:45:56 -0700 (PDT) Date: Thu, 30 Jul 2026 12:45:53 +0300 From: Nikolay Kulikov To: Mohit Mishra Cc: Greg Kroah-Hartman , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] staging: rtl8723bs: fix underflow logic in swing index calculations Message-ID: References: <20260729172707.13333-1-mishraloopmohit@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260729172707.13333-1-mishraloopmohit@gmail.com> On Wed, Jul 29, 2026 at 10:57:07PM +0530, Mohit Mishra wrote: > 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. There is no need to try to fix the check in BBSWING mode - it never executes and can be removed. The ODM_TxPwrTrackSetPwr_8723B() function is always called with 'Method' set to 'MIX_MODE' (see hal/HalPhyRf.c, lines 252 and 255). Thanks, Nikolay > > 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 > >