* the firmware and hence to take the mutex.
* Avoid the deadlock by unlocking the mutex here.
*/
- mutex_unlock(&mvm->mutex);
- thermal_notify_framework(mvm->tz_device.tzone,
- mvm->tz_device.fw_trips_index[ths_crossed]);
- mutex_lock(&mvm->mutex);
+ if (mvm->tz_device.tzone) {
+ struct iwl_mvm_thermal_device *tz_dev = &mvm->tz_device;
+
+ mutex_unlock(&mvm->mutex);
+ thermal_notify_framework(tz_dev->tzone,
+ tz_dev->fw_trips_index[ths_crossed]);
+ mutex_lock(&mvm->mutex);
+ }
#endif /* CONFIG_THERMAL */
}
lockdep_assert_held(&mvm->mutex);
+ if (!mvm->tz_device.tzone)
+ return -EINVAL;
+
/* The driver holds array of temperature trips that are unsorted
* and uncompressed, the FW should get it compressed and sorted
*/
/* compress temp_trips to cmd array, remove uninitialized values*/
- for (i = 0; i < IWL_MAX_DTS_TRIPS; i++)
+ for (i = 0; i < IWL_MAX_DTS_TRIPS; i++) {
if (mvm->tz_device.temp_trips[i] != S16_MIN) {
cmd.thresholds[idx++] =
cpu_to_le16(mvm->tz_device.temp_trips[i]);
}
+ }
cmd.num_temps = cpu_to_le32(idx);
if (!idx)
IWL_DEBUG_TEMP(mvm,
"Failed to register to thermal zone (err = %ld)\n",
PTR_ERR(mvm->tz_device.tzone));
+ mvm->tz_device.tzone = NULL;
return;
}
return ret;
}
+ /* can happen if the registration failed */
+ if (!mvm->cooling_dev.cdev)
+ return -EINVAL;
+
if (op == CTDP_CMD_OPERATION_START)
mvm->cooling_dev.cur_state = budget;
.set_cur_state = iwl_mvm_tcool_set_cur_state,
};
-int iwl_mvm_cooling_device_register(struct iwl_mvm *mvm)
+static void iwl_mvm_cooling_device_register(struct iwl_mvm *mvm)
{
char name[] = "iwlwifi";
- if (!iwl_mvm_is_ctdp_supported(mvm)) {
- mvm->cooling_dev.cdev = NULL;
-
- return 0;
- }
+ if (!iwl_mvm_is_ctdp_supported(mvm))
+ return;
BUILD_BUG_ON(ARRAY_SIZE(name) >= THERMAL_NAME_LENGTH);
IWL_DEBUG_TEMP(mvm,
"Failed to register to cooling device (err = %ld)\n",
PTR_ERR(mvm->cooling_dev.cdev));
- return PTR_ERR(mvm->cooling_dev.cdev);
+ mvm->cooling_dev.cdev = NULL;
+ return;
}
-
- return 0;
}
static void iwl_mvm_thermal_zone_unregister(struct iwl_mvm *mvm)
{
- if (!iwl_mvm_is_tt_in_fw(mvm))
+ if (!iwl_mvm_is_tt_in_fw(mvm) || !mvm->tz_device.tzone)
return;
- if (mvm->tz_device.tzone) {
- IWL_DEBUG_TEMP(mvm, "Thermal zone device unregister\n");
- thermal_zone_device_unregister(mvm->tz_device.tzone);
- mvm->tz_device.tzone = NULL;
- }
+ IWL_DEBUG_TEMP(mvm, "Thermal zone device unregister\n");
+ thermal_zone_device_unregister(mvm->tz_device.tzone);
+ mvm->tz_device.tzone = NULL;
}
static void iwl_mvm_cooling_device_unregister(struct iwl_mvm *mvm)
{
- if (!iwl_mvm_is_ctdp_supported(mvm))
+ if (!iwl_mvm_is_ctdp_supported(mvm) || !mvm->cooling_dev.cdev)
return;
- if (mvm->cooling_dev.cdev) {
- IWL_DEBUG_TEMP(mvm, "Cooling device unregister\n");
- thermal_cooling_device_unregister(mvm->cooling_dev.cdev);
- mvm->cooling_dev.cdev = NULL;
- }
+ IWL_DEBUG_TEMP(mvm, "Cooling device unregister\n");
+ thermal_cooling_device_unregister(mvm->cooling_dev.cdev);
+ mvm->cooling_dev.cdev = NULL;
}
#endif /* CONFIG_THERMAL */