@@ -302,6 +302,19 @@ static void rfkill_set_block(struct rfkill *rfkill, bool blocked)
302
302
rfkill_event (rfkill );
303
303
}
304
304
305
+ static void rfkill_update_global_state (enum rfkill_type type , bool blocked )
306
+ {
307
+ int i ;
308
+
309
+ if (type != RFKILL_TYPE_ALL ) {
310
+ rfkill_global_states [type ].cur = blocked ;
311
+ return ;
312
+ }
313
+
314
+ for (i = 0 ; i < NUM_RFKILL_TYPES ; i ++ )
315
+ rfkill_global_states [i ].cur = blocked ;
316
+ }
317
+
305
318
#ifdef CONFIG_RFKILL_INPUT
306
319
static atomic_t rfkill_input_disabled = ATOMIC_INIT (0 );
307
320
@@ -319,15 +332,7 @@ static void __rfkill_switch_all(const enum rfkill_type type, bool blocked)
319
332
{
320
333
struct rfkill * rfkill ;
321
334
322
- if (type == RFKILL_TYPE_ALL ) {
323
- int i ;
324
-
325
- for (i = 0 ; i < NUM_RFKILL_TYPES ; i ++ )
326
- rfkill_global_states [i ].cur = blocked ;
327
- } else {
328
- rfkill_global_states [type ].cur = blocked ;
329
- }
330
-
335
+ rfkill_update_global_state (type , blocked );
331
336
list_for_each_entry (rfkill , & rfkill_list , node ) {
332
337
if (rfkill -> type != type && type != RFKILL_TYPE_ALL )
333
338
continue ;
@@ -1166,15 +1171,8 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
1166
1171
1167
1172
mutex_lock (& rfkill_global_mutex );
1168
1173
1169
- if (ev .op == RFKILL_OP_CHANGE_ALL ) {
1170
- if (ev .type == RFKILL_TYPE_ALL ) {
1171
- enum rfkill_type i ;
1172
- for (i = 0 ; i < NUM_RFKILL_TYPES ; i ++ )
1173
- rfkill_global_states [i ].cur = ev .soft ;
1174
- } else {
1175
- rfkill_global_states [ev .type ].cur = ev .soft ;
1176
- }
1177
- }
1174
+ if (ev .op == RFKILL_OP_CHANGE_ALL )
1175
+ rfkill_update_global_state (ev .type , ev .soft );
1178
1176
1179
1177
list_for_each_entry (rfkill , & rfkill_list , node ) {
1180
1178
if (rfkill -> idx != ev .idx && ev .op != RFKILL_OP_CHANGE_ALL )
@@ -1263,10 +1261,8 @@ static struct miscdevice rfkill_miscdev = {
1263
1261
static int __init rfkill_init (void )
1264
1262
{
1265
1263
int error ;
1266
- int i ;
1267
1264
1268
- for (i = 0 ; i < NUM_RFKILL_TYPES ; i ++ )
1269
- rfkill_global_states [i ].cur = !rfkill_default_state ;
1265
+ rfkill_update_global_state (RFKILL_TYPE_ALL , !rfkill_default_state );
1270
1266
1271
1267
error = class_register (& rfkill_class );
1272
1268
if (error )
0 commit comments