@@ -27,25 +27,16 @@ static ssize_t platform_profile_choices_show(struct device *dev,
27
27
char * buf )
28
28
{
29
29
int len = 0 ;
30
- int err , i ;
31
-
32
- err = mutex_lock_interruptible (& profile_lock );
33
- if (err )
34
- return err ;
30
+ int i ;
35
31
36
- if (!cur_profile ) {
37
- mutex_unlock (& profile_lock );
38
- return - ENODEV ;
39
- }
40
-
41
- for_each_set_bit (i , cur_profile -> choices , PLATFORM_PROFILE_LAST ) {
42
- if (len == 0 )
43
- len += sysfs_emit_at (buf , len , "%s" , profile_names [i ]);
44
- else
45
- len += sysfs_emit_at (buf , len , " %s" , profile_names [i ]);
32
+ scoped_cond_guard (mutex_intr , return - ERESTARTSYS , & profile_lock ) {
33
+ if (!cur_profile )
34
+ return - ENODEV ;
35
+ for_each_set_bit (i , cur_profile -> choices , PLATFORM_PROFILE_LAST )
36
+ len += sysfs_emit_at (buf , len , len ? " %s" : "%s" , profile_names [i ]);
46
37
}
47
38
len += sysfs_emit_at (buf , len , "\n" );
48
- mutex_unlock ( & profile_lock );
39
+
49
40
return len ;
50
41
}
51
42
@@ -56,20 +47,15 @@ static ssize_t platform_profile_show(struct device *dev,
56
47
enum platform_profile_option profile = PLATFORM_PROFILE_BALANCED ;
57
48
int err ;
58
49
59
- err = mutex_lock_interruptible ( & profile_lock );
60
- if (err )
61
- return err ;
50
+ scoped_cond_guard ( mutex_intr , return - ERESTARTSYS , & profile_lock ) {
51
+ if (! cur_profile )
52
+ return - ENODEV ;
62
53
63
- if (! cur_profile ) {
64
- mutex_unlock ( & profile_lock );
65
- return - ENODEV ;
54
+ err = cur_profile -> profile_get ( cur_profile , & profile );
55
+ if ( err )
56
+ return err ;
66
57
}
67
58
68
- err = cur_profile -> profile_get (cur_profile , & profile );
69
- mutex_unlock (& profile_lock );
70
- if (err )
71
- return err ;
72
-
73
59
/* Check that profile is valid index */
74
60
if (WARN_ON ((profile < 0 ) || (profile >= ARRAY_SIZE (profile_names ))))
75
61
return - EIO ;
@@ -88,28 +74,21 @@ static ssize_t platform_profile_store(struct device *dev,
88
74
if (i < 0 )
89
75
return - EINVAL ;
90
76
91
- err = mutex_lock_interruptible ( & profile_lock );
92
- if (err )
93
- return err ;
77
+ scoped_cond_guard ( mutex_intr , return - ERESTARTSYS , & profile_lock ) {
78
+ if (! cur_profile )
79
+ return - ENODEV ;
94
80
95
- if (!cur_profile ) {
96
- mutex_unlock (& profile_lock );
97
- return - ENODEV ;
98
- }
81
+ /* Check that platform supports this profile choice */
82
+ if (!test_bit (i , cur_profile -> choices ))
83
+ return - EOPNOTSUPP ;
99
84
100
- /* Check that platform supports this profile choice */
101
- if (!test_bit (i , cur_profile -> choices )) {
102
- mutex_unlock (& profile_lock );
103
- return - EOPNOTSUPP ;
85
+ err = cur_profile -> profile_set (cur_profile , i );
86
+ if (err )
87
+ return err ;
104
88
}
105
89
106
- err = cur_profile -> profile_set (cur_profile , i );
107
- if (!err )
108
- sysfs_notify (acpi_kobj , NULL , "platform_profile" );
90
+ sysfs_notify (acpi_kobj , NULL , "platform_profile" );
109
91
110
- mutex_unlock (& profile_lock );
111
- if (err )
112
- return err ;
113
92
return count ;
114
93
}
115
94
@@ -140,36 +119,28 @@ int platform_profile_cycle(void)
140
119
enum platform_profile_option next ;
141
120
int err ;
142
121
143
- err = mutex_lock_interruptible ( & profile_lock );
144
- if (err )
145
- return err ;
122
+ scoped_cond_guard ( mutex_intr , return - ERESTARTSYS , & profile_lock ) {
123
+ if (! cur_profile )
124
+ return - ENODEV ;
146
125
147
- if (!cur_profile ) {
148
- mutex_unlock (& profile_lock );
149
- return - ENODEV ;
150
- }
126
+ err = cur_profile -> profile_get (cur_profile , & profile );
127
+ if (err )
128
+ return err ;
151
129
152
- err = cur_profile -> profile_get (cur_profile , & profile );
153
- if (err ) {
154
- mutex_unlock (& profile_lock );
155
- return err ;
156
- }
130
+ next = find_next_bit_wrap (cur_profile -> choices , PLATFORM_PROFILE_LAST ,
131
+ profile + 1 );
157
132
158
- next = find_next_bit_wrap ( cur_profile -> choices , PLATFORM_PROFILE_LAST ,
159
- profile + 1 ) ;
133
+ if ( WARN_ON ( next == PLATFORM_PROFILE_LAST ))
134
+ return - EINVAL ;
160
135
161
- if ( WARN_ON ( next == PLATFORM_PROFILE_LAST )) {
162
- mutex_unlock ( & profile_lock );
163
- return - EINVAL ;
136
+ err = cur_profile -> profile_set ( cur_profile , next );
137
+ if ( err )
138
+ return err ;
164
139
}
165
140
166
- err = cur_profile -> profile_set (cur_profile , next );
167
- mutex_unlock (& profile_lock );
168
-
169
- if (!err )
170
- sysfs_notify (acpi_kobj , NULL , "platform_profile" );
141
+ sysfs_notify (acpi_kobj , NULL , "platform_profile" );
171
142
172
- return err ;
143
+ return 0 ;
173
144
}
174
145
EXPORT_SYMBOL_GPL (platform_profile_cycle );
175
146
0 commit comments