@@ -27,25 +27,16 @@ static ssize_t platform_profile_choices_show(struct device *dev,
2727 char * buf )
2828{
2929 int len = 0 ;
30- int err , i ;
31-
32- err = mutex_lock_interruptible (& profile_lock );
33- if (err )
34- return err ;
30+ int i ;
3531
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 ]);
4637 }
4738 len += sysfs_emit_at (buf , len , "\n" );
48- mutex_unlock ( & profile_lock );
39+
4940 return len ;
5041}
5142
@@ -56,20 +47,15 @@ static ssize_t platform_profile_show(struct device *dev,
5647 enum platform_profile_option profile = PLATFORM_PROFILE_BALANCED ;
5748 int err ;
5849
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 ;
6253
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 ;
6657 }
6758
68- err = cur_profile -> profile_get (cur_profile , & profile );
69- mutex_unlock (& profile_lock );
70- if (err )
71- return err ;
72-
7359 /* Check that profile is valid index */
7460 if (WARN_ON ((profile < 0 ) || (profile >= ARRAY_SIZE (profile_names ))))
7561 return - EIO ;
@@ -88,28 +74,21 @@ static ssize_t platform_profile_store(struct device *dev,
8874 if (i < 0 )
8975 return - EINVAL ;
9076
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 ;
9480
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 ;
9984
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 ;
10488 }
10589
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" );
10991
110- mutex_unlock (& profile_lock );
111- if (err )
112- return err ;
11392 return count ;
11493}
11594
@@ -140,36 +119,28 @@ int platform_profile_cycle(void)
140119 enum platform_profile_option next ;
141120 int err ;
142121
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 ;
146125
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 ;
151129
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 );
157132
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 ;
160135
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 ;
164139 }
165140
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" );
171142
172- return err ;
143+ return 0 ;
173144}
174145EXPORT_SYMBOL_GPL (platform_profile_cycle );
175146
0 commit comments