]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: ath12k: Replace lock/unlock with guard()
authorRipan Deuri <quic_rdeuri@quicinc.com>
Mon, 3 Nov 2025 11:21:11 +0000 (16:51 +0530)
committerJeff Johnson <jeff.johnson@oss.qualcomm.com>
Wed, 5 Nov 2025 15:16:56 +0000 (07:16 -0800)
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>
drivers/net/wireless/ath/ath12k/debugfs_sta.c
drivers/net/wireless/ath/ath12k/mac.c

index dde3efed4b60b91055b69aa324c5daecadc1aa15..585c40bd295171f2d2e0d4994499b6d3e016e302 100644 (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;
 }
 
index 4647c555cb489360df4ed7061268809aeafd4c24..aa80afebb69ea77e6715d90aae12bf50fe718b8c 100644 (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);