All of lore.kernel.org
 help / color / mirror / Atom feed
From: "João Paulo Rechi Vita" <jprvita@gmail.com>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>,
	"Darren Hart" <dvhart@infradead.org>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	platform-driver-x86@vger.kernel.org, linux-api@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux@endlessm.com,
	"João Paulo Rechi Vita" <jprvita@endlessm.com>
Subject: [PATCHv2 05/10] rfkill: Factor rfkill_global_states[].cur assignments
Date: Mon, 22 Feb 2016 11:36:36 -0500	[thread overview]
Message-ID: <1456159001-20307-6-git-send-email-jprvita@endlessm.com> (raw)
In-Reply-To: <1456159001-20307-1-git-send-email-jprvita@endlessm.com>

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>
---
 net/rfkill/core.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index 56d79cb..8b96869 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)
 		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);
 
@@ -319,15 +332,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;
@@ -1164,15 +1169,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)
@@ -1261,10 +1259,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


  parent reply	other threads:[~2016-02-22 16:37 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-22 16:36 [PATCHv2 00/10] RFKill airplane-mode indicator João Paulo Rechi Vita
2016-02-22 16:36 ` João Paulo Rechi Vita
2016-02-22 16:36 ` [PATCHv2 01/10] rfkill: Improve documentation language João Paulo Rechi Vita
2016-02-22 16:36 ` [PATCHv2 02/10] rfkill: Remove extra blank line João Paulo Rechi Vita
2016-02-22 16:36   ` João Paulo Rechi Vita
2016-02-22 16:36 ` [PATCHv2 03/10] rfkill: Point to the correct deprecated doc location João Paulo Rechi Vita
2016-02-22 16:36 ` [PATCHv2 04/10] rfkill: Move "state" sysfs file back to stable João Paulo Rechi Vita
2016-02-23 20:45   ` Pavel Machek
2016-02-22 16:36 ` João Paulo Rechi Vita [this message]
2016-02-22 16:36 ` [PATCHv2 06/10] rfkill: Add documentation about LED triggers João Paulo Rechi Vita
2016-02-22 16:36 ` [PATCHv2 07/10] rfkill: Create "rfkill-airplane-mode" LED trigger João Paulo Rechi Vita
2016-02-22 16:36 ` [PATCHv2 08/10] rfkill: Use switch to demux userspace operations João Paulo Rechi Vita
2016-02-26 17:59   ` Jouni Malinen
2016-02-26 17:59     ` Jouni Malinen
2016-02-29 22:30     ` João Paulo Rechi Vita
2016-02-29 22:39       ` Jouni Malinen
2016-03-01 13:43         ` Johannes Berg
2016-03-01 16:15           ` João Paulo Rechi Vita
2016-03-01 16:15             ` João Paulo Rechi Vita
2016-03-08 14:01             ` João Paulo Rechi Vita
2016-02-22 16:36 ` [PATCHv2 09/10] rfkill: Userspace control for airplane mode João Paulo Rechi Vita
2016-02-22 19:31   ` [PATCHv3] " João Paulo Rechi Vita
2016-02-23 20:45   ` [PATCHv2 09/10] " Pavel Machek
2016-02-23 20:55     ` Johannes Berg
2016-02-23 21:45       ` Pavel Machek
2016-02-24  9:01         ` Johannes Berg
2016-02-24  9:01           ` Johannes Berg
2016-02-24 10:46           ` custom ioctl-based interface to control LED in networking (was Re: [PATCHv2 09/10] rfkill: Userspace control for airplane mode) Pavel Machek
2016-02-24 11:01             ` Johannes Berg
2016-02-24 12:14               ` Pavel Machek
2016-02-24 13:31                 ` Johannes Berg
2016-02-24 13:31                   ` Johannes Berg
2016-02-25  9:06                   ` Pavel Machek
2016-02-22 16:36 ` [PATCHv2 10/10] rfkill: Notify userspace of airplane-mode state changes João Paulo Rechi Vita
2016-02-22 17:00 ` [PATCHv2 00/10] RFKill airplane-mode indicator Dan Williams
2016-02-22 19:35   ` João Paulo Rechi Vita

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=1456159001-20307-6-git-send-email-jprvita@endlessm.com \
    --to=jprvita@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dvhart@infradead.org \
    --cc=johannes@sipsolutions.net \
    --cc=jprvita@endlessm.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@endlessm.com \
    --cc=netdev@vger.kernel.org \
    --cc=platform-driver-x86@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: link
Be 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.