From: "João Paulo Rechi Vita" <jprvita@gmail.com> To: johannes@sipsolutions.net Cc: marcel@holtmann.org, linux-wireless@vger.kernel.org, davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, jprvita@endlessm.com, linux@endlessm.com Subject: [PATCH 8/8] rfkill: Factor common code Date: Tue, 19 Jan 2016 10:42:43 -0500 [thread overview] Message-ID: <1453218163-31998-9-git-send-email-jprvita@endlessm.com> (raw) In-Reply-To: <1453218163-31998-1-git-send-email-jprvita@endlessm.com> Factor all assignments to rfkill_global_states[].cur to rfkill_update_global_state(), and also make accesses to rfkill_global_states[].cur go through rfkill_get_global_sw_state(). Signed-off-by: João Paulo Rechi Vita <jprvita@endlessm.com> --- net/rfkill/core.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 0b9d5bf..ae3d15a 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -300,6 +300,19 @@ static void rfkill_set_block(struct rfkill *rfkill, bool blocked) rfkill_event(rfkill); } +static void rfkill_update_global_state(enum rfkill_type type, bool blocked) +{ + int i; + + if (type != RFKILL_TYPE_ALL) { + rfkill_global_states[type].cur = blocked; + return; + } + + for (i = 0; i < NUM_RFKILL_TYPES; i++) + rfkill_global_states[i].cur = blocked; +} + #ifdef CONFIG_RFKILL_INPUT static atomic_t rfkill_input_disabled = ATOMIC_INIT(0); @@ -317,15 +330,7 @@ static void __rfkill_switch_all(const enum rfkill_type type, bool blocked) { struct rfkill *rfkill; - if (type == RFKILL_TYPE_ALL) { - int i; - - for (i = 0; i < NUM_RFKILL_TYPES; i++) - rfkill_global_states[i].cur = blocked; - } else { - rfkill_global_states[type].cur = blocked; - } - + rfkill_update_global_state(type, blocked); list_for_each_entry(rfkill, &rfkill_list, node) { if (rfkill->type != type && type != RFKILL_TYPE_ALL) continue; @@ -877,7 +882,7 @@ static void rfkill_sync_work(struct work_struct *work) rfkill = container_of(work, struct rfkill, sync_work); mutex_lock(&rfkill_global_mutex); - cur = rfkill_global_states[rfkill->type].cur; + cur = rfkill_get_global_sw_state(rfkill->type); rfkill_set_block(rfkill, cur); mutex_unlock(&rfkill_global_mutex); } @@ -1116,15 +1121,8 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf, mutex_lock(&rfkill_global_mutex); - if (ev.op == RFKILL_OP_CHANGE_ALL) { - if (ev.type == RFKILL_TYPE_ALL) { - enum rfkill_type i; - for (i = 0; i < NUM_RFKILL_TYPES; i++) - rfkill_global_states[i].cur = ev.soft; - } else { - rfkill_global_states[ev.type].cur = ev.soft; - } - } + if (ev.op == RFKILL_OP_CHANGE_ALL) + rfkill_update_global_state(ev.type, ev.soft); list_for_each_entry(rfkill, &rfkill_list, node) { if (rfkill->idx != ev.idx && ev.op != RFKILL_OP_CHANGE_ALL) @@ -1213,10 +1211,8 @@ static struct miscdevice rfkill_miscdev = { static int __init rfkill_init(void) { int error; - int i; - for (i = 0; i < NUM_RFKILL_TYPES; i++) - rfkill_global_states[i].cur = !rfkill_default_state; + rfkill_update_global_state(RFKILL_TYPE_ALL, !rfkill_default_state); error = class_register(&rfkill_class); if (error) -- 2.5.0
WARNING: multiple messages have this Message-ID (diff)
From: "João Paulo Rechi Vita" <jprvita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> To: johannes-cdvu00un1VgdHxzADdlk8Q@public.gmane.org Cc: marcel-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org, linux-wireless-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org, netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, jprvita-6IF/jdPJHihWk0Htik3J/w@public.gmane.org, linux-6IF/jdPJHihWk0Htik3J/w@public.gmane.org Subject: [PATCH 8/8] rfkill: Factor common code Date: Tue, 19 Jan 2016 10:42:43 -0500 [thread overview] Message-ID: <1453218163-31998-9-git-send-email-jprvita@endlessm.com> (raw) In-Reply-To: <1453218163-31998-1-git-send-email-jprvita-6IF/jdPJHihWk0Htik3J/w@public.gmane.org> Factor all assignments to rfkill_global_states[].cur to rfkill_update_global_state(), and also make accesses to rfkill_global_states[].cur go through rfkill_get_global_sw_state(). Signed-off-by: João Paulo Rechi Vita <jprvita-6IF/jdPJHihWk0Htik3J/w@public.gmane.org> --- net/rfkill/core.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 0b9d5bf..ae3d15a 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -300,6 +300,19 @@ static void rfkill_set_block(struct rfkill *rfkill, bool blocked) rfkill_event(rfkill); } +static void rfkill_update_global_state(enum rfkill_type type, bool blocked) +{ + int i; + + if (type != RFKILL_TYPE_ALL) { + rfkill_global_states[type].cur = blocked; + return; + } + + for (i = 0; i < NUM_RFKILL_TYPES; i++) + rfkill_global_states[i].cur = blocked; +} + #ifdef CONFIG_RFKILL_INPUT static atomic_t rfkill_input_disabled = ATOMIC_INIT(0); @@ -317,15 +330,7 @@ static void __rfkill_switch_all(const enum rfkill_type type, bool blocked) { struct rfkill *rfkill; - if (type == RFKILL_TYPE_ALL) { - int i; - - for (i = 0; i < NUM_RFKILL_TYPES; i++) - rfkill_global_states[i].cur = blocked; - } else { - rfkill_global_states[type].cur = blocked; - } - + rfkill_update_global_state(type, blocked); list_for_each_entry(rfkill, &rfkill_list, node) { if (rfkill->type != type && type != RFKILL_TYPE_ALL) continue; @@ -877,7 +882,7 @@ static void rfkill_sync_work(struct work_struct *work) rfkill = container_of(work, struct rfkill, sync_work); mutex_lock(&rfkill_global_mutex); - cur = rfkill_global_states[rfkill->type].cur; + cur = rfkill_get_global_sw_state(rfkill->type); rfkill_set_block(rfkill, cur); mutex_unlock(&rfkill_global_mutex); } @@ -1116,15 +1121,8 @@ static ssize_t rfkill_fop_write(struct file *file, const char __user *buf, mutex_lock(&rfkill_global_mutex); - if (ev.op == RFKILL_OP_CHANGE_ALL) { - if (ev.type == RFKILL_TYPE_ALL) { - enum rfkill_type i; - for (i = 0; i < NUM_RFKILL_TYPES; i++) - rfkill_global_states[i].cur = ev.soft; - } else { - rfkill_global_states[ev.type].cur = ev.soft; - } - } + if (ev.op == RFKILL_OP_CHANGE_ALL) + rfkill_update_global_state(ev.type, ev.soft); list_for_each_entry(rfkill, &rfkill_list, node) { if (rfkill->idx != ev.idx && ev.op != RFKILL_OP_CHANGE_ALL) @@ -1213,10 +1211,8 @@ static struct miscdevice rfkill_miscdev = { static int __init rfkill_init(void) { int error; - int i; - for (i = 0; i < NUM_RFKILL_TYPES; i++) - rfkill_global_states[i].cur = !rfkill_default_state; + rfkill_update_global_state(RFKILL_TYPE_ALL, !rfkill_default_state); error = class_register(&rfkill_class); if (error) -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-01-19 15:44 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2016-01-19 15:42 [PATCH 0/8] General RFKill improvements João Paulo Rechi Vita 2016-01-19 15:42 ` [PATCH 1/8] rfkill: Documentation and style fixes João Paulo Rechi Vita 2016-01-19 20:11 ` Johannes Berg 2016-01-19 20:11 ` Johannes Berg 2016-01-19 20:19 ` João Paulo Rechi Vita 2016-01-19 20:19 ` João Paulo Rechi Vita 2016-01-19 15:42 ` [PATCH 2/8] rfkill: Improve code readability João Paulo Rechi Vita 2016-01-19 15:42 ` [PATCH 3/8] " João Paulo Rechi Vita 2016-01-19 15:42 ` [PATCH 4/8] rfkill: Remove obsolete "claim" sysfs interface João Paulo Rechi Vita 2016-01-19 15:42 ` [PATCH 5/8] rfkill: Remove obsolete "state" " João Paulo Rechi Vita 2016-01-19 20:15 ` Johannes Berg 2016-01-19 20:36 ` João Paulo Rechi Vita 2016-01-19 20:36 ` João Paulo Rechi Vita 2016-01-19 20:44 ` Johannes Berg 2016-01-19 15:42 ` [PATCH 6/8] rfkill: Move user_state_from_blocked() close to its user João Paulo Rechi Vita 2016-01-19 15:42 ` [PATCH 7/8] rfkill: Update userspace API documentation João Paulo Rechi Vita 2016-01-19 15:42 ` João Paulo Rechi Vita [this message] 2016-01-19 15:42 ` [PATCH 8/8] rfkill: Factor common code João Paulo Rechi Vita 2016-01-19 17:39 ` kbuild test robot 2016-01-19 17:39 ` kbuild test robot 2016-01-19 20:32 ` João Paulo Rechi Vita 2016-01-19 20:32 ` João Paulo Rechi Vita 2016-01-19 18:15 ` kbuild test robot 2016-01-26 13:08 ` [PATCH 0/8] General RFKill improvements Johannes Berg
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1453218163-31998-9-git-send-email-jprvita@endlessm.com \ --to=jprvita@gmail.com \ --cc=davem@davemloft.net \ --cc=johannes@sipsolutions.net \ --cc=jprvita@endlessm.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-wireless@vger.kernel.org \ --cc=linux@endlessm.com \ --cc=marcel@holtmann.org \ --cc=netdev@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.