13
13
#include <linux/bitfield.h>
14
14
#include <linux/bitops.h>
15
15
#include <linux/bug.h>
16
+ #include <linux/cleanup.h>
16
17
#include <linux/debugfs.h>
17
18
#include <linux/device.h>
18
19
#include <linux/dmi.h>
@@ -204,7 +205,7 @@ static int ideapad_shared_init(struct ideapad_private *priv)
204
205
{
205
206
int ret ;
206
207
207
- mutex_lock (& ideapad_shared_mutex );
208
+ guard ( mutex ) (& ideapad_shared_mutex );
208
209
209
210
if (!ideapad_shared ) {
210
211
ideapad_shared = priv ;
@@ -214,19 +215,15 @@ static int ideapad_shared_init(struct ideapad_private *priv)
214
215
ret = - EINVAL ;
215
216
}
216
217
217
- mutex_unlock (& ideapad_shared_mutex );
218
-
219
218
return ret ;
220
219
}
221
220
222
221
static void ideapad_shared_exit (struct ideapad_private * priv )
223
222
{
224
- mutex_lock (& ideapad_shared_mutex );
223
+ guard ( mutex ) (& ideapad_shared_mutex );
225
224
226
225
if (ideapad_shared == priv )
227
226
ideapad_shared = NULL ;
228
-
229
- mutex_unlock (& ideapad_shared_mutex );
230
227
}
231
228
232
229
/*
@@ -840,36 +837,33 @@ static int dytc_profile_set(struct platform_profile_handler *pprof,
840
837
unsigned long output ;
841
838
int err ;
842
839
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
+ }
858
860
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 ;
864
864
}
865
865
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 ;
873
867
}
874
868
875
869
static void dytc_profile_refresh (struct ideapad_private * priv )
@@ -878,9 +872,8 @@ static void dytc_profile_refresh(struct ideapad_private *priv)
878
872
unsigned long output ;
879
873
int err , perfmode ;
880
874
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 );
884
877
if (err )
885
878
return ;
886
879
@@ -1809,11 +1802,11 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
1809
1802
struct ideapad_wmi_private * wpriv = dev_get_drvdata (& wdev -> dev );
1810
1803
struct ideapad_private * priv ;
1811
1804
1812
- mutex_lock (& ideapad_shared_mutex );
1805
+ guard ( mutex ) (& ideapad_shared_mutex );
1813
1806
1814
1807
priv = ideapad_shared ;
1815
1808
if (!priv )
1816
- goto unlock ;
1809
+ return ;
1817
1810
1818
1811
switch (wpriv -> event ) {
1819
1812
case IDEAPAD_WMI_EVENT_ESC :
@@ -1847,8 +1840,6 @@ static void ideapad_wmi_notify(struct wmi_device *wdev, union acpi_object *data)
1847
1840
1848
1841
break ;
1849
1842
}
1850
- unlock :
1851
- mutex_unlock (& ideapad_shared_mutex );
1852
1843
}
1853
1844
1854
1845
static const struct ideapad_wmi_private ideapad_wmi_context_esc = {
0 commit comments