platform/x86: ideapad-laptop: use cleanup.h

Use cleanup.h helpers to simplify some code paths.

Signed-off-by: Gergo Koteles <soyer@irl.hu>
Link: https://lore.kernel.org/r/851d4180f1df5a10ca6e2feaf429611f1c0ccc88.1720515666.git.soyer@irl.hu
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
This commit is contained in:
Gergo Koteles 2024-07-09 11:33:05 +02:00 committed by Ilpo Järvinen
parent f6bd2f633b
commit 7c25946f34
No known key found for this signature in database
GPG Key ID: 59AC4F6153E5CE31

View File

@ -13,6 +13,7 @@
#include <linux/bitfield.h>
#include <linux/bitops.h>
#include <linux/bug.h>
#include <linux/cleanup.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/dmi.h>
@ -204,7 +205,7 @@ static int ideapad_shared_init(struct ideapad_private *priv)
{
int ret;
mutex_lock(&ideapad_shared_mutex);
guard(mutex)(&ideapad_shared_mutex);
if (!ideapad_shared) {
ideapad_shared = priv;
@ -214,19 +215,15 @@ static int ideapad_shared_init(struct ideapad_private *priv)
ret = -EINVAL;
}
mutex_unlock(&ideapad_shared_mutex);
return ret;
}
static void ideapad_shared_exit(struct ideapad_private *priv)
{
mutex_lock(&ideapad_shared_mutex);
guard(mutex)(&ideapad_shared_mutex);
if (ideapad_shared == priv)
ideapad_shared = NULL;
mutex_unlock(&ideapad_shared_mutex);
}
/*
@ -840,36 +837,33 @@ static int dytc_profile_set(struct platform_profile_handler *pprof,
unsigned long output;
int err;
err = mutex_lock_interruptible(&dytc->mutex);
if (err)
return err;
scoped_guard(mutex_intr, &dytc->mutex) {
if (profile == PLATFORM_PROFILE_BALANCED) {
/* To get back to balanced mode we just issue a reset command */
err = eval_dytc(priv->adev->handle, DYTC_CMD_RESET, NULL);
if (err)
return err;
} else {
int perfmode;
if (profile == PLATFORM_PROFILE_BALANCED) {
/* To get back to balanced mode we just issue a reset command */
err = eval_dytc(priv->adev->handle, DYTC_CMD_RESET, NULL);
if (err)
goto unlock;
} else {
int perfmode;
err = convert_profile_to_dytc(profile, &perfmode);
if (err)
return err;
err = convert_profile_to_dytc(profile, &perfmode);
if (err)
goto unlock;
/* Determine if we are in CQL mode. This alters the commands we do */
err = dytc_cql_command(priv,
DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1),
&output);
if (err)
return err;
}
/* Determine if we are in CQL mode. This alters the commands we do */
err = dytc_cql_command(priv, DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1),
&output);
if (err)
goto unlock;
/* Success - update current profile */
dytc->current_profile = profile;
return 0;
}
/* Success - update current profile */
dytc->current_profile = profile;
unlock:
mutex_unlock(&dytc->mutex);
return err;
return -EINTR;
}
static void dytc_profile_refresh(struct ideapad_private *priv)
@ -878,9 +872,8 @@ static void dytc_profile_refresh(struct ideapad_private *priv)
unsigned long output;
int err, perfmode;
mutex_lock(&priv->dytc->mutex);
err = dytc_cql_command(priv, DYTC_CMD_GET, &output);
mutex_unlock(&priv->dytc->mutex);
scoped_guard(mutex, &priv->dytc->mutex)
err = dytc_cql_command(priv, DYTC_CMD_GET, &output);
if (err)
return;
@ -1809,11 +1802,11 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
struct ideapad_wmi_private *wpriv = dev_get_drvdata(&wdev->dev);
struct ideapad_private *priv;
mutex_lock(&ideapad_shared_mutex);
guard(mutex)(&ideapad_shared_mutex);
priv = ideapad_shared;
if (!priv)
goto unlock;
return;
switch (wpriv->event) {
case IDEAPAD_WMI_EVENT_ESC:
@ -1847,8 +1840,6 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
break;
}
unlock:
mutex_unlock(&ideapad_shared_mutex);
}
static const struct ideapad_wmi_private ideapad_wmi_context_esc = {