]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: ath12k: refactor per-radio thermal hwmon setup and cleanup
authorMaharaja Kennadyrajan <maharaja.kennadyrajan@oss.qualcomm.com>
Mon, 13 Apr 2026 15:38:38 +0000 (21:08 +0530)
committerJeff Johnson <jeff.johnson@oss.qualcomm.com>
Thu, 30 Apr 2026 21:24:09 +0000 (14:24 -0700)
Both the error path in thermal registration and the normal thermal unregister
path performed the same hwmon device unregistration and pointer cleanup.
Consolidate this logic into a single helper to reduce code duplication and ensure
consistent cleanup across all paths. Add a helper to set up the hwmon registration
during thermal registration to keep symmetry with thermal cleanup.

Tested-on: QCN9274 hw2.0 PCI WLAN.WBE.1.6-01243-QCAHKSWPL_SILICONZ-1
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c5-00302-QCAHMTSWPL_V1.0_V2.0_SILICONZ-1.115823.3

Signed-off-by: Maharaja Kennadyrajan <maharaja.kennadyrajan@oss.qualcomm.com>
Reviewed-by: Rameshkumar Sundaram <rameshkumar.sundaram@oss.qualcomm.com>
Reviewed-by: Baochen Qiang <baochen.qiang@oss.qualcomm.com>
Link: https://patch.msgid.link/20260413153840.1969931-4-maharaja.kennadyrajan@oss.qualcomm.com
Signed-off-by: Jeff Johnson <jeff.johnson@oss.qualcomm.com>
drivers/net/wireless/ath/ath12k/thermal.c

index 4f76622e8117d557b1efa3646c1736e31dbdffca..6f70c11c109824a542d139bd41b96a22297caf46 100644 (file)
@@ -130,59 +130,70 @@ static struct attribute *ath12k_hwmon_attrs[] = {
 };
 ATTRIBUTE_GROUPS(ath12k_hwmon);
 
-int ath12k_thermal_register(struct ath12k_base *ab)
+static int ath12k_thermal_setup_radio(struct ath12k_base *ab, int i)
+{
+       struct ath12k *ar;
+       int ret;
+
+       ar = ab->pdevs[i].ar;
+       if (!ar)
+               return 0;
+
+       ar->thermal.hwmon_dev =
+               hwmon_device_register_with_groups(&ar->ah->hw->wiphy->dev,
+                                                 "ath12k_hwmon", ar,
+                                                 ath12k_hwmon_groups);
+       if (IS_ERR(ar->thermal.hwmon_dev)) {
+               ret = PTR_ERR(ar->thermal.hwmon_dev);
+               ar->thermal.hwmon_dev = NULL;
+               ath12k_err(ar->ab, "failed to register hwmon device: %d\n",
+                          ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static void ath12k_thermal_cleanup_radio(struct ath12k_base *ab, int i)
 {
        struct ath12k *ar;
-       int i, j, ret;
+
+       ar = ab->pdevs[i].ar;
+       if (!ar)
+               return;
+
+       hwmon_device_unregister(ar->thermal.hwmon_dev);
+       ar->thermal.hwmon_dev = NULL;
+}
+
+int ath12k_thermal_register(struct ath12k_base *ab)
+{
+       int i, ret;
 
        if (!IS_REACHABLE(CONFIG_HWMON))
                return 0;
 
        for (i = 0; i < ab->num_radios; i++) {
-               ar = ab->pdevs[i].ar;
-               if (!ar)
-                       continue;
-
-               ar->thermal.hwmon_dev =
-                       hwmon_device_register_with_groups(&ar->ah->hw->wiphy->dev,
-                                                         "ath12k_hwmon", ar,
-                                                         ath12k_hwmon_groups);
-               if (IS_ERR(ar->thermal.hwmon_dev)) {
-                       ret = PTR_ERR(ar->thermal.hwmon_dev);
-                       ar->thermal.hwmon_dev = NULL;
-                       ath12k_err(ar->ab, "failed to register hwmon device: %d\n",
-                                  ret);
-                       for (j = i - 1; j >= 0; j--) {
-                               ar = ab->pdevs[j].ar;
-                               if (!ar)
-                                       continue;
-
-                               hwmon_device_unregister(ar->thermal.hwmon_dev);
-                               ar->thermal.hwmon_dev = NULL;
-                       }
-                       return ret;
-               }
+               ret = ath12k_thermal_setup_radio(ab, i);
+               if (ret)
+                       goto out;
        }
 
        return 0;
+out:
+       for (i--; i >= 0; i--)
+               ath12k_thermal_cleanup_radio(ab, i);
+
+       return ret;
 }
 
 void ath12k_thermal_unregister(struct ath12k_base *ab)
 {
-       struct ath12k *ar;
        int i;
 
        if (!IS_REACHABLE(CONFIG_HWMON))
                return;
 
-       for (i = 0; i < ab->num_radios; i++) {
-               ar = ab->pdevs[i].ar;
-               if (!ar)
-                       continue;
-
-               if (ar->thermal.hwmon_dev) {
-                       hwmon_device_unregister(ar->thermal.hwmon_dev);
-                       ar->thermal.hwmon_dev = NULL;
-               }
-       }
+       for (i = 0; i < ab->num_radios; i++)
+               ath12k_thermal_cleanup_radio(ab, i);
 }