Skip to content

Commit 7c25946

Browse files
soyersoyerij-intel
authored andcommitted
platform/x86: ideapad-laptop: use cleanup.h
Use cleanup.h helpers to simplify some code paths. Signed-off-by: Gergo Koteles <[email protected]> Link: https://lore.kernel.org/r/851d4180f1df5a10ca6e2feaf429611f1c0ccc88.1720515666.git.soyer@irl.hu Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Ilpo Järvinen <[email protected]>
1 parent f6bd2f6 commit 7c25946

File tree

1 file changed

+31
-40
lines changed

1 file changed

+31
-40
lines changed

drivers/platform/x86/ideapad-laptop.c

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/bitfield.h>
1414
#include <linux/bitops.h>
1515
#include <linux/bug.h>
16+
#include <linux/cleanup.h>
1617
#include <linux/debugfs.h>
1718
#include <linux/device.h>
1819
#include <linux/dmi.h>
@@ -204,7 +205,7 @@ static int ideapad_shared_init(struct ideapad_private *priv)
204205
{
205206
int ret;
206207

207-
mutex_lock(&ideapad_shared_mutex);
208+
guard(mutex)(&ideapad_shared_mutex);
208209

209210
if (!ideapad_shared) {
210211
ideapad_shared = priv;
@@ -214,19 +215,15 @@ static int ideapad_shared_init(struct ideapad_private *priv)
214215
ret = -EINVAL;
215216
}
216217

217-
mutex_unlock(&ideapad_shared_mutex);
218-
219218
return ret;
220219
}
221220

222221
static void ideapad_shared_exit(struct ideapad_private *priv)
223222
{
224-
mutex_lock(&ideapad_shared_mutex);
223+
guard(mutex)(&ideapad_shared_mutex);
225224

226225
if (ideapad_shared == priv)
227226
ideapad_shared = NULL;
228-
229-
mutex_unlock(&ideapad_shared_mutex);
230227
}
231228

232229
/*
@@ -840,36 +837,33 @@ static int dytc_profile_set(struct platform_profile_handler *pprof,
840837
unsigned long output;
841838
int err;
842839

843-
err = mutex_lock_interruptible(&dytc->mutex);
844-
if (err)
845-
return err;
846-
847-
if (profile == PLATFORM_PROFILE_BALANCED) {
848-
/* To get back to balanced mode we just issue a reset command */
849-
err = eval_dytc(priv->adev->handle, DYTC_CMD_RESET, NULL);
850-
if (err)
851-
goto unlock;
852-
} else {
853-
int perfmode;
854-
855-
err = convert_profile_to_dytc(profile, &perfmode);
856-
if (err)
857-
goto unlock;
840+
scoped_guard(mutex_intr, &dytc->mutex) {
841+
if (profile == PLATFORM_PROFILE_BALANCED) {
842+
/* To get back to balanced mode we just issue a reset command */
843+
err = eval_dytc(priv->adev->handle, DYTC_CMD_RESET, NULL);
844+
if (err)
845+
return err;
846+
} else {
847+
int perfmode;
848+
849+
err = convert_profile_to_dytc(profile, &perfmode);
850+
if (err)
851+
return err;
852+
853+
/* Determine if we are in CQL mode. This alters the commands we do */
854+
err = dytc_cql_command(priv,
855+
DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1),
856+
&output);
857+
if (err)
858+
return err;
859+
}
858860

859-
/* Determine if we are in CQL mode. This alters the commands we do */
860-
err = dytc_cql_command(priv, DYTC_SET_COMMAND(DYTC_FUNCTION_MMC, perfmode, 1),
861-
&output);
862-
if (err)
863-
goto unlock;
861+
/* Success - update current profile */
862+
dytc->current_profile = profile;
863+
return 0;
864864
}
865865

866-
/* Success - update current profile */
867-
dytc->current_profile = profile;
868-
869-
unlock:
870-
mutex_unlock(&dytc->mutex);
871-
872-
return err;
866+
return -EINTR;
873867
}
874868

875869
static void dytc_profile_refresh(struct ideapad_private *priv)
@@ -878,9 +872,8 @@ static void dytc_profile_refresh(struct ideapad_private *priv)
878872
unsigned long output;
879873
int err, perfmode;
880874

881-
mutex_lock(&priv->dytc->mutex);
882-
err = dytc_cql_command(priv, DYTC_CMD_GET, &output);
883-
mutex_unlock(&priv->dytc->mutex);
875+
scoped_guard(mutex, &priv->dytc->mutex)
876+
err = dytc_cql_command(priv, DYTC_CMD_GET, &output);
884877
if (err)
885878
return;
886879

@@ -1809,11 +1802,11 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
18091802
struct ideapad_wmi_private *wpriv = dev_get_drvdata(&wdev->dev);
18101803
struct ideapad_private *priv;
18111804

1812-
mutex_lock(&ideapad_shared_mutex);
1805+
guard(mutex)(&ideapad_shared_mutex);
18131806

18141807
priv = ideapad_shared;
18151808
if (!priv)
1816-
goto unlock;
1809+
return;
18171810

18181811
switch (wpriv->event) {
18191812
case IDEAPAD_WMI_EVENT_ESC:
@@ -1847,8 +1840,6 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
18471840

18481841
break;
18491842
}
1850-
unlock:
1851-
mutex_unlock(&ideapad_shared_mutex);
18521843
}
18531844

18541845
static const struct ideapad_wmi_private ideapad_wmi_context_esc = {

0 commit comments

Comments
 (0)