Skip to content

Commit 9487bd6

Browse files
jprvitajmberg-intel
authored andcommitted
rfkill: Factor rfkill_global_states[].cur assignments
Factor all assignments to rfkill_global_states[].cur into a single function rfkill_update_global_state(). Signed-off-by: João Paulo Rechi Vita <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 4b636dc commit 9487bd6

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

net/rfkill/core.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,19 @@ static void rfkill_set_block(struct rfkill *rfkill, bool blocked)
302302
rfkill_event(rfkill);
303303
}
304304

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+
305318
#ifdef CONFIG_RFKILL_INPUT
306319
static atomic_t rfkill_input_disabled = ATOMIC_INIT(0);
307320

@@ -319,15 +332,7 @@ static void __rfkill_switch_all(const enum rfkill_type type, bool blocked)
319332
{
320333
struct rfkill *rfkill;
321334

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);
331336
list_for_each_entry(rfkill, &rfkill_list, node) {
332337
if (rfkill->type != type && type != RFKILL_TYPE_ALL)
333338
continue;
@@ -1166,15 +1171,8 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf,
11661171

11671172
mutex_lock(&rfkill_global_mutex);
11681173

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);
11781176

11791177
list_for_each_entry(rfkill, &rfkill_list, node) {
11801178
if (rfkill->idx != ev.idx && ev.op != RFKILL_OP_CHANGE_ALL)
@@ -1263,10 +1261,8 @@ static struct miscdevice rfkill_miscdev = {
12631261
static int __init rfkill_init(void)
12641262
{
12651263
int error;
1266-
int i;
12671264

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);
12701266

12711267
error = class_register(&rfkill_class);
12721268
if (error)

0 commit comments

Comments
 (0)