From: Maharaja Kennadyrajan Date: Mon, 13 Apr 2026 15:38:38 +0000 (+0530) Subject: wifi: ath12k: refactor per-radio thermal hwmon setup and cleanup X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd93e8c23ebbd72e9aa799199b14c8433585f747;p=thirdparty%2Fkernel%2Flinux.git 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 Reviewed-by: Rameshkumar Sundaram Reviewed-by: Baochen Qiang Link: https://patch.msgid.link/20260413153840.1969931-4-maharaja.kennadyrajan@oss.qualcomm.com Signed-off-by: Jeff Johnson --- diff --git a/drivers/net/wireless/ath/ath12k/thermal.c b/drivers/net/wireless/ath/ath12k/thermal.c index 4f76622e8117d..6f70c11c10982 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); }