diff options
author | João Paulo Rechi Vita <jprvita@gmail.com> | 2016-02-22 11:36:36 -0500 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2016-02-24 03:13:11 -0500 |
commit | 9487bd6b96a98ee07661a7b5e6f6afce67e2860b (patch) | |
tree | 950592ee8bba089f5215e649f69109f26b0d4d46 /net/rfkill | |
parent | 4b636dc659ffbca8bc8069dcdf5ae5c2d088a163 (diff) |
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 <jprvita@endlessm.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/rfkill')
-rw-r--r-- | net/rfkill/core.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/net/rfkill/core.c b/net/rfkill/core.c index f843eeeac46d..a8c05e18da58 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c | |||
@@ -302,6 +302,19 @@ static void rfkill_set_block(struct rfkill *rfkill, bool blocked) | |||
302 | rfkill_event(rfkill); | 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 | #ifdef CONFIG_RFKILL_INPUT | 318 | #ifdef CONFIG_RFKILL_INPUT |
306 | static atomic_t rfkill_input_disabled = ATOMIC_INIT(0); | 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 | struct rfkill *rfkill; | 333 | struct rfkill *rfkill; |
321 | 334 | ||
322 | if (type == RFKILL_TYPE_ALL) { | 335 | rfkill_update_global_state(type, blocked); |
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 | |||
331 | list_for_each_entry(rfkill, &rfkill_list, node) { | 336 | list_for_each_entry(rfkill, &rfkill_list, node) { |
332 | if (rfkill->type != type && type != RFKILL_TYPE_ALL) | 337 | if (rfkill->type != type && type != RFKILL_TYPE_ALL) |
333 | continue; | 338 | continue; |
@@ -1166,15 +1171,8 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf, | |||
1166 | 1171 | ||
1167 | mutex_lock(&rfkill_global_mutex); | 1172 | mutex_lock(&rfkill_global_mutex); |
1168 | 1173 | ||
1169 | if (ev.op == RFKILL_OP_CHANGE_ALL) { | 1174 | if (ev.op == RFKILL_OP_CHANGE_ALL) |
1170 | if (ev.type == RFKILL_TYPE_ALL) { | 1175 | rfkill_update_global_state(ev.type, ev.soft); |
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 | } | ||
1178 | 1176 | ||
1179 | list_for_each_entry(rfkill, &rfkill_list, node) { | 1177 | list_for_each_entry(rfkill, &rfkill_list, node) { |
1180 | if (rfkill->idx != ev.idx && ev.op != RFKILL_OP_CHANGE_ALL) | 1178 | if (rfkill->idx != ev.idx && ev.op != RFKILL_OP_CHANGE_ALL) |
@@ -1263,10 +1261,8 @@ static struct miscdevice rfkill_miscdev = { | |||
1263 | static int __init rfkill_init(void) | 1261 | static int __init rfkill_init(void) |
1264 | { | 1262 | { |
1265 | int error; | 1263 | int error; |
1266 | int i; | ||
1267 | 1264 | ||
1268 | for (i = 0; i < NUM_RFKILL_TYPES; i++) | 1265 | rfkill_update_global_state(RFKILL_TYPE_ALL, !rfkill_default_state); |
1269 | rfkill_global_states[i].cur = !rfkill_default_state; | ||
1270 | 1266 | ||
1271 | error = class_register(&rfkill_class); | 1267 | error = class_register(&rfkill_class); |
1272 | if (error) | 1268 | if (error) |