Remove the dytc_profile_available check from dytc_profile_set(), that function only gets called if the platform_profile_handler was registered, so the check is not necessary. Make tpacpi_dytc_profile_init() return -ENODEV when it does not register the platform_profile() handler this will cause dytc_profile_driver_data.flags.init to not get set, which in turn will cause the dytc_profile_exit() call to get skipped. Together this avoids the need to have the dytc_profile_available variable at all, since the information is now duplicated in the dytc_profile_driver_data.flags.init flag. Note this leaves a weirdly indented code-block behind, this is deliberately done to make what actually changes in this commit clear. This will be fixed-up in the next commit. Signed-off-by: Hans de Goede <hdegoede@xxxxxxxxxx> --- drivers/platform/x86/thinkpad_acpi.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index 4c8050a0655a..cdc4028be341 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -9950,7 +9950,6 @@ static struct ibm_struct proxsensor_driver_data = { #define DYTC_ENABLE_CQL DYTC_SET_COMMAND(DYTC_FUNCTION_CQL, DYTC_MODE_BALANCE, 1) -static bool dytc_profile_available; static enum platform_profile_option dytc_current_profile; static atomic_t dytc_ignore_event = ATOMIC_INIT(0); static DEFINE_MUTEX(dytc_mutex); @@ -10054,9 +10053,6 @@ static int dytc_profile_set(struct platform_profile_handler *pprof, int output; int err; - if (!dytc_profile_available) - return -ENODEV; - err = mutex_lock_interruptible(&dytc_mutex); if (err) return err; @@ -10127,7 +10123,6 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) set_bit(PLATFORM_PROFILE_BALANCED, dytc_profile.choices); set_bit(PLATFORM_PROFILE_PERFORMANCE, dytc_profile.choices); - dytc_profile_available = false; err = dytc_command(DYTC_CMD_QUERY, &output); if (err) return err; @@ -10136,7 +10131,10 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) dytc_version = (output >> DYTC_QUERY_REV_BIT) & 0xF; /* Check DYTC is enabled and supports mode setting */ - if (dytc_version >= 5) { + if (dytc_version < 5) + return -ENODEV; + + { dbg_printk(TPACPI_DBG_INIT, "DYTC version %d: thermal mode available\n", dytc_version); /* @@ -10156,9 +10154,8 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) * don't quit terminally. */ if (err) - return 0; + return -ENODEV; - dytc_profile_available = true; /* Ensure initial values are correct */ dytc_profile_refresh(); } @@ -10167,10 +10164,7 @@ static int tpacpi_dytc_profile_init(struct ibm_init_struct *iibm) static void dytc_profile_exit(void) { - if (dytc_profile_available) { - dytc_profile_available = false; - platform_profile_remove(); - } + platform_profile_remove(); } static struct ibm_struct dytc_profile_driver_data = { -- 2.31.1