linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings
@ 2025-08-04  3:03 Baochen Qiang
  2025-08-04  3:03 ` [PATCH ath-next 1/2] wifi: ath12k: initialize eirp_power before use Baochen Qiang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Baochen Qiang @ 2025-08-04  3:03 UTC (permalink / raw)
  To: Jeff Johnson, Baochen Qiang, Vasanthakumar Thiagarajan
  Cc: Jeff Johnson, linux-wireless, ath12k, linux-kernel, Baochen Qiang,
	kernel test robot, Dan Carpenter

Fix below two Smatch warnings:

1#
drivers/net/wireless/ath/ath12k/mac.c:10069
ath12k_mac_fill_reg_tpc_info() error: uninitialized symbol 'eirp_power'.

2#
drivers/net/wireless/ath/ath12k/mac.c:9812
ath12k_mac_parse_tx_pwr_env() error: buffer overflow 'local_non_psd->power' 5 <= 15
drivers/net/wireless/ath/ath12k/mac.c:9812
ath12k_mac_parse_tx_pwr_env() error: buffer overflow 'reg_non_psd->power' 5 <= 15

Signed-off-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
---
Baochen Qiang (2):
      wifi: ath12k: initialize eirp_power before use
      wifi: ath12k: fix overflow warning on num_pwr_levels

 drivers/net/wireless/ath/ath12k/mac.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
---
base-commit: 4cedae6335644a5858e1bc2c367aedc10482b654
change-id: 20250716-ath12k-fix-smatch-warning-on-6g-vlp-a97cb86f3a16

Best regards,
-- 
Baochen Qiang <baochen.qiang@oss.qualcomm.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH ath-next 1/2] wifi: ath12k: initialize eirp_power before use
  2025-08-04  3:03 [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings Baochen Qiang
@ 2025-08-04  3:03 ` Baochen Qiang
  2025-08-04  3:03 ` [PATCH ath-next 2/2] wifi: ath12k: fix overflow warning on num_pwr_levels Baochen Qiang
  2025-08-06 14:10 ` [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings Jeff Johnson
  2 siblings, 0 replies; 5+ messages in thread
From: Baochen Qiang @ 2025-08-04  3:03 UTC (permalink / raw)
  To: Jeff Johnson, Baochen Qiang, Vasanthakumar Thiagarajan
  Cc: Jeff Johnson, linux-wireless, ath12k, linux-kernel, Baochen Qiang,
	kernel test robot, Dan Carpenter

Currently, at the end of ath12k_mac_fill_reg_tpc_info(), the
reg_tpc_info struct is populated, including the following:
reg_tpc_info->is_psd_power = is_psd_power;
reg_tpc_info->eirp_power = eirp_power;

Kernel test robot complains on uninitialized symbol:
drivers/net/wireless/ath/ath12k/mac.c:10069
ath12k_mac_fill_reg_tpc_info() error: uninitialized symbol 'eirp_power'

This is because there are some code paths that never set eirp_power, so
the assignment of reg_tpc_info->eirp_power can come from an
uninitialized variable. Functionally this is OK since the eirp_power
only has meaning when is_psd_power is true, and all code paths which set
is_psd_power to true also set eirp_power. However, to keep the robot
happy, always initialize eirp_power before use.

Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c5-00284-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1

Fixes: aeda163bb0c7 ("wifi: ath12k: fill parameters for vdev set TPC power WMI command")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202505180927.tbNWr3vE-lkp@intel.com/
Signed-off-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
---
 drivers/net/wireless/ath/ath12k/mac.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c
index bd1ec3b2c084169b841146931c54b6106f7006f6..8295480e8b1eeaa3e69cca823e6745733ade50e0 100644
--- a/drivers/net/wireless/ath/ath12k/mac.c
+++ b/drivers/net/wireless/ath/ath12k/mac.c
@@ -11228,8 +11228,8 @@ void ath12k_mac_fill_reg_tpc_info(struct ath12k *ar,
 	struct ieee80211_channel *chan, *temp_chan;
 	u8 pwr_lvl_idx, num_pwr_levels, pwr_reduction;
 	bool is_psd_power = false, is_tpe_present = false;
-	s8 max_tx_power[ATH12K_NUM_PWR_LEVELS],
-		psd_power, tx_power, eirp_power;
+	s8 max_tx_power[ATH12K_NUM_PWR_LEVELS], psd_power, tx_power;
+	s8 eirp_power = 0;
 	struct ath12k_vif *ahvif = arvif->ahvif;
 	u16 start_freq, center_freq;
 	u8 reg_6ghz_power_mode;

-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH ath-next 2/2] wifi: ath12k: fix overflow warning on num_pwr_levels
  2025-08-04  3:03 [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings Baochen Qiang
  2025-08-04  3:03 ` [PATCH ath-next 1/2] wifi: ath12k: initialize eirp_power before use Baochen Qiang
@ 2025-08-04  3:03 ` Baochen Qiang
  2025-08-06 14:10 ` [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings Jeff Johnson
  2 siblings, 0 replies; 5+ messages in thread
From: Baochen Qiang @ 2025-08-04  3:03 UTC (permalink / raw)
  To: Jeff Johnson, Baochen Qiang, Vasanthakumar Thiagarajan
  Cc: Jeff Johnson, linux-wireless, ath12k, linux-kernel, Baochen Qiang,
	kernel test robot, Dan Carpenter

From: Baochen Qiang <quic_bqiang@quicinc.com>

In ath12k_mac_parse_tx_pwr_env(), for the non-PSD case num_pwr_levels is
limited by ATH12K_NUM_PWR_LEVELS which is 16:

	if (tpc_info->num_pwr_levels > ATH12K_NUM_PWR_LEVELS)
		tpc_info->num_pwr_levels = ATH12K_NUM_PWR_LEVELS;

Then it is used to iterate entries in local_non_psd->power[] and
reg_non_psd->power[]:

	for (i = 0; i < tpc_info->num_pwr_levels; i++) {
		tpc_info->tpe[i] = min(local_non_psd->power[i],
				       reg_non_psd->power[i]) / 2;

Since the two array are of size 5, Smatch warns:

drivers/net/wireless/ath/ath12k/mac.c:9812
ath12k_mac_parse_tx_pwr_env() error: buffer overflow 'local_non_psd->power' 5 <= 15
drivers/net/wireless/ath/ath12k/mac.c:9812
ath12k_mac_parse_tx_pwr_env() error: buffer overflow 'reg_non_psd->power' 5 <= 15

This is a false positive as there is already implicit limitation:

	tpc_info->num_pwr_levels = max(local_non_psd->count,
				       reg_non_psd->count);

meaning it won't exceed 5.

However, to make robot happy, add explicit limit there.

Also add the same to the PSD case, although no warning due to
ATH12K_NUM_PWR_LEVELS equals IEEE80211_TPE_PSD_ENTRIES_320MHZ.

Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c5-00284-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1

Fixes: cccbb9d0dd6a ("wifi: ath12k: add parse of transmit power envelope element")
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/r/202505180703.Kr9OfQRP-lkp@intel.com/
Signed-off-by: Baochen Qiang <quic_bqiang@quicinc.com>
---
 drivers/net/wireless/ath/ath12k/mac.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/ath/ath12k/mac.c b/drivers/net/wireless/ath/ath12k/mac.c
index 8295480e8b1eeaa3e69cca823e6745733ade50e0..57c81ba988ad3c7c3037286c6c093cef4c4f8116 100644
--- a/drivers/net/wireless/ath/ath12k/mac.c
+++ b/drivers/net/wireless/ath/ath12k/mac.c
@@ -11435,8 +11435,10 @@ static void ath12k_mac_parse_tx_pwr_env(struct ath12k *ar,
 
 		tpc_info->num_pwr_levels = max(local_psd->count,
 					       reg_psd->count);
-		if (tpc_info->num_pwr_levels > ATH12K_NUM_PWR_LEVELS)
-			tpc_info->num_pwr_levels = ATH12K_NUM_PWR_LEVELS;
+		tpc_info->num_pwr_levels =
+				min3(tpc_info->num_pwr_levels,
+				     IEEE80211_TPE_PSD_ENTRIES_320MHZ,
+				     ATH12K_NUM_PWR_LEVELS);
 
 		for (i = 0; i < tpc_info->num_pwr_levels; i++) {
 			tpc_info->tpe[i] = min(local_psd->power[i],
@@ -11451,8 +11453,10 @@ static void ath12k_mac_parse_tx_pwr_env(struct ath12k *ar,
 
 		tpc_info->num_pwr_levels = max(local_non_psd->count,
 					       reg_non_psd->count);
-		if (tpc_info->num_pwr_levels > ATH12K_NUM_PWR_LEVELS)
-			tpc_info->num_pwr_levels = ATH12K_NUM_PWR_LEVELS;
+		tpc_info->num_pwr_levels =
+				min3(tpc_info->num_pwr_levels,
+				     IEEE80211_TPE_EIRP_ENTRIES_320MHZ,
+				     ATH12K_NUM_PWR_LEVELS);
 
 		for (i = 0; i < tpc_info->num_pwr_levels; i++) {
 			tpc_info->tpe[i] = min(local_non_psd->power[i],

-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings
  2025-08-04  3:03 [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings Baochen Qiang
  2025-08-04  3:03 ` [PATCH ath-next 1/2] wifi: ath12k: initialize eirp_power before use Baochen Qiang
  2025-08-04  3:03 ` [PATCH ath-next 2/2] wifi: ath12k: fix overflow warning on num_pwr_levels Baochen Qiang
@ 2025-08-06 14:10 ` Jeff Johnson
  2025-08-11  3:38   ` Baochen Qiang
  2 siblings, 1 reply; 5+ messages in thread
From: Jeff Johnson @ 2025-08-06 14:10 UTC (permalink / raw)
  To: Baochen Qiang, Jeff Johnson, Baochen Qiang,
	Vasanthakumar Thiagarajan
  Cc: linux-wireless, ath12k, linux-kernel, kernel test robot,
	Dan Carpenter

On 8/3/2025 8:03 PM, Baochen Qiang wrote:
> Fix below two Smatch warnings:
> 
> 1#
> drivers/net/wireless/ath/ath12k/mac.c:10069
> ath12k_mac_fill_reg_tpc_info() error: uninitialized symbol 'eirp_power'.
> 
> 2#
> drivers/net/wireless/ath/ath12k/mac.c:9812
> ath12k_mac_parse_tx_pwr_env() error: buffer overflow 'local_non_psd->power' 5 <= 15
> drivers/net/wireless/ath/ath12k/mac.c:9812
> ath12k_mac_parse_tx_pwr_env() error: buffer overflow 'reg_non_psd->power' 5 <= 15
> 
> Signed-off-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
> ---
> Baochen Qiang (2):
>       wifi: ath12k: initialize eirp_power before use
>       wifi: ath12k: fix overflow warning on num_pwr_levels
> 
>  drivers/net/wireless/ath/ath12k/mac.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)

Since this is fixing smatch issues I plan on taking this through ath-current
instead of ath-next.

/jeff

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings
  2025-08-06 14:10 ` [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings Jeff Johnson
@ 2025-08-11  3:38   ` Baochen Qiang
  0 siblings, 0 replies; 5+ messages in thread
From: Baochen Qiang @ 2025-08-11  3:38 UTC (permalink / raw)
  To: Jeff Johnson, Jeff Johnson, Baochen Qiang,
	Vasanthakumar Thiagarajan
  Cc: linux-wireless, ath12k, linux-kernel, kernel test robot,
	Dan Carpenter



On 8/6/2025 10:10 PM, Jeff Johnson wrote:
> On 8/3/2025 8:03 PM, Baochen Qiang wrote:
>> Fix below two Smatch warnings:
>>
>> 1#
>> drivers/net/wireless/ath/ath12k/mac.c:10069
>> ath12k_mac_fill_reg_tpc_info() error: uninitialized symbol 'eirp_power'.
>>
>> 2#
>> drivers/net/wireless/ath/ath12k/mac.c:9812
>> ath12k_mac_parse_tx_pwr_env() error: buffer overflow 'local_non_psd->power' 5 <= 15
>> drivers/net/wireless/ath/ath12k/mac.c:9812
>> ath12k_mac_parse_tx_pwr_env() error: buffer overflow 'reg_non_psd->power' 5 <= 15
>>
>> Signed-off-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
>> ---
>> Baochen Qiang (2):
>>       wifi: ath12k: initialize eirp_power before use
>>       wifi: ath12k: fix overflow warning on num_pwr_levels
>>
>>  drivers/net/wireless/ath/ath12k/mac.c | 16 ++++++++++------
>>  1 file changed, 10 insertions(+), 6 deletions(-)
> 
> Since this is fixing smatch issues I plan on taking this through ath-current
> instead of ath-next.

Sure, fine with me.

> 
> /jeff


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-08-11  3:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-04  3:03 [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings Baochen Qiang
2025-08-04  3:03 ` [PATCH ath-next 1/2] wifi: ath12k: initialize eirp_power before use Baochen Qiang
2025-08-04  3:03 ` [PATCH ath-next 2/2] wifi: ath12k: fix overflow warning on num_pwr_levels Baochen Qiang
2025-08-06 14:10 ` [PATCH ath-next 0/2] wifi: ath12k: fix 2 instances of Smatch warnings Jeff Johnson
2025-08-11  3:38   ` Baochen Qiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).