summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaharaja Kennadyrajan <maharaja.kennadyrajan@oss.qualcomm.com>2026-04-13 21:08:38 +0530
committerJeff Johnson <jeff.johnson@oss.qualcomm.com>2026-04-30 14:24:09 -0700
commitcd93e8c23ebbd72e9aa799199b14c8433585f747 (patch)
tree0b58dacf096e1545c884a9b3870244c961a4bb0b
parent612556eb774f19f0ad64b5f72e890943b95a1339 (diff)
downloadlinux-cd93e8c23ebbd72e9aa799199b14c8433585f747.tar.gz
linux-cd93e8c23ebbd72e9aa799199b14c8433585f747.zip
wifi: ath12k: refactor per-radio thermal hwmon setup and cleanup
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>
-rw-r--r--drivers/net/wireless/ath/ath12k/thermal.c83
1 files changed, 47 insertions, 36 deletions
diff --git a/drivers/net/wireless/ath/ath12k/thermal.c b/drivers/net/wireless/ath/ath12k/thermal.c
index 4f76622e8117..6f70c11c1098 100644
--- a/drivers/net/wireless/ath/ath12k/thermal.c
+++ b/drivers/net/wireless/ath/ath12k/thermal.c
@@ -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);
}