wifi: ath12k: Replace lock/unlock with guard()

Use guard(wiphy)(...) and guard(spinlock_bh)(...) in:

ath12k_dbg_sta_dump_rx_stats()
ath12k_mac_op_link_sta_statistics()

The guard() API ensures locks are automatically released when the scope
exits, reducing the risk of missing unlocks in error paths and improving
code readability.

Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.4.1-00199-QCAHKSWPL_SILICONZ-1
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3

Signed-off-by: Ripan Deuri <quic_rdeuri@quicinc.com>
Reviewed-by: Karthikeyan Periyasamy <karthikeyan.periyasamy@oss.qualcomm.com>
Reviewed-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
Link: https://patch.msgid.link/20251103112111.2260639-13-quic_rdeuri@quicinc.com
Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
This commit is contained in:
Ripan Deuri 2025-11-03 16:51:11 +05:30 committed by Jeff Johnson
parent 96b42732bc
commit f87034a757
2 changed files with 13 additions and 30 deletions

View File

@ -153,41 +153,32 @@ static ssize_t ath12k_dbg_sta_dump_rx_stats(struct file *file,
bool he_rates_avail;
struct ath12k *ar;
wiphy_lock(ah->hw->wiphy);
guard(wiphy)(ah->hw->wiphy);
if (!(BIT(link_id) & ahsta->links_map)) {
wiphy_unlock(ah->hw->wiphy);
if (!(BIT(link_id) & ahsta->links_map))
return -ENOENT;
}
arsta = wiphy_dereference(ah->hw->wiphy, ahsta->link[link_id]);
if (!arsta || !arsta->arvif->ar) {
wiphy_unlock(ah->hw->wiphy);
if (!arsta || !arsta->arvif->ar)
return -ENOENT;
}
ar = arsta->arvif->ar;
u8 *buf __free(kfree) = kzalloc(size, GFP_KERNEL);
if (!buf) {
ret = -ENOENT;
goto out;
}
if (!buf)
return -ENOMEM;
dp = ath12k_ab_to_dp(ar->ab);
spin_lock_bh(&dp->dp_lock);
guard(spinlock_bh)(&dp->dp_lock);
link_peer = ath12k_dp_link_peer_find_by_addr(dp, arsta->addr);
if (!link_peer) {
ret = -ENOENT;
goto unlock;
}
if (!link_peer)
return -ENOENT;
rx_stats = link_peer->peer_stats.rx_stats;
if (!rx_stats) {
ret = -ENOENT;
goto unlock;
}
if (!rx_stats)
return -ENOENT;
len += scnprintf(buf + len, size - len, "RX peer stats:\n\n");
len += scnprintf(buf + len, size - len, "Num of MSDUs: %llu\n",
@ -247,13 +238,8 @@ static ssize_t ath12k_dbg_sta_dump_rx_stats(struct file *file,
len += ath12k_dbg_sta_dump_rate_stats(buf, len, size, he_rates_avail,
&rx_stats->byte_stats);
unlock:
spin_unlock_bh(&dp->dp_lock);
if (len)
ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
out:
wiphy_unlock(ah->hw->wiphy);
return ret;
}

View File

@ -12792,12 +12792,10 @@ void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw,
db2dbm = test_bit(WMI_TLV_SERVICE_HW_DB2DBM_CONVERSION_SUPPORT,
ar->ab->wmi_ab.svc_map);
spin_lock_bh(&ar->ab->dp->dp_lock);
guard(spinlock_bh)(&ar->ab->dp->dp_lock);
peer = ath12k_dp_link_peer_find_by_addr(ar->ab->dp, arsta->addr);
if (!peer) {
spin_unlock_bh(&ar->ab->dp->dp_lock);
if (!peer)
return;
}
link_sinfo->rx_duration = peer->rx_duration;
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_RX_DURATION);
@ -12853,7 +12851,6 @@ void ath12k_mac_op_link_sta_statistics(struct ieee80211_hw *hw,
link_sinfo->tx_failed = peer->tx_retry_failed;
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_RETRIES);
link_sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_FAILED);
spin_unlock_bh(&ar->ab->dp->dp_lock);
}
EXPORT_SYMBOL(ath12k_mac_op_link_sta_statistics);