Skip to content

Commit

Permalink
wifi: ath12k: Fix uninitialized variable access in ath12k_mac_allocat…
Browse files Browse the repository at this point in the history
…e() function

Currently, the uninitialized variable 'ab' is accessed in the
ath12k_mac_allocate() function. Initialize 'ab' with the first radio device
present in the hardware abstraction handle (ah). Additionally, move the
default setting procedure from the pdev mapping iteration to the total
radio calculating iteration for better code readability. Perform the
maximum radio validation check for total_radio to ensure that both num_hw
and radio_per_hw are validated indirectly, as these variables are derived
from total_radio. This also fixes the below Smatch static checker warning.

Smatch warning:
ath12k_mac_allocate() error: uninitialized symbol 'ab'

Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.3.1-00173-QCAHKSWPL_SILICONZ-1

Fixes: a343d97 ("wifi: ath12k: move struct ath12k_hw from per device to group")
Signed-off-by: Karthikeyan Periyasamy <quic_periyasa@quicinc.com>
Acked-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
Acked-by: Kalle Valo <kvalo@kernel.org>
Link: https://patch.msgid.link/20250112071630.4059410-5-quic_periyasa@quicinc.com
Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
  • Loading branch information
Karthikeyan Periyasamy authored and Jeff Johnson committed Jan 14, 2025
1 parent 54fcdcf commit 4aae869
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions drivers/net/wireless/ath/ath12k/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -11383,8 +11383,20 @@ int ath12k_mac_allocate(struct ath12k_hw_group *ag)
u8 radio_per_hw;

total_radio = 0;
for (i = 0; i < ag->num_devices; i++)
total_radio += ag->ab[i]->num_radios;
for (i = 0; i < ag->num_devices; i++) {
ab = ag->ab[i];
if (!ab)
continue;

ath12k_mac_set_device_defaults(ab);
total_radio += ab->num_radios;
}

if (!total_radio)
return -EINVAL;

if (WARN_ON(total_radio > ATH12K_GROUP_MAX_RADIO))
return -ENOSPC;

/* All pdev get combined and register as single wiphy based on
* hardware group which participate in multi-link operation else
Expand All @@ -11397,14 +11409,16 @@ int ath12k_mac_allocate(struct ath12k_hw_group *ag)

num_hw = total_radio / radio_per_hw;

if (WARN_ON(num_hw >= ATH12K_GROUP_MAX_RADIO))
return -ENOSPC;

ag->num_hw = 0;
device_id = 0;
mac_id = 0;
for (i = 0; i < num_hw; i++) {
for (j = 0; j < radio_per_hw; j++) {
if (device_id >= ag->num_devices || !ag->ab[device_id]) {
ret = -ENOSPC;
goto err;
}

ab = ag->ab[device_id];
pdev_map[j].ab = ab;
pdev_map[j].pdev_idx = mac_id;
Expand All @@ -11416,10 +11430,11 @@ int ath12k_mac_allocate(struct ath12k_hw_group *ag)
if (mac_id >= ab->num_radios) {
mac_id = 0;
device_id++;
ath12k_mac_set_device_defaults(ab);
}
}

ab = pdev_map->ab;

ah = ath12k_mac_hw_allocate(ag, pdev_map, radio_per_hw);
if (!ah) {
ath12k_warn(ab, "failed to allocate mac80211 hw device for hw_idx %d\n",
Expand Down

0 comments on commit 4aae869

Please sign in to comment.