From patchwork Mon Feb 22 16:36:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jo=C3=A3o_Paulo_Rechi_Vita?= X-Patchwork-Id: 8380061 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 58DFFC0553 for ; Mon, 22 Feb 2016 16:43:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 71EAC204FC for ; Mon, 22 Feb 2016 16:43:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BFD62039E for ; Mon, 22 Feb 2016 16:43:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755176AbcBVQlq (ORCPT ); Mon, 22 Feb 2016 11:41:46 -0500 Received: from mail-qk0-f178.google.com ([209.85.220.178]:33992 "EHLO mail-qk0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752502AbcBVQhD (ORCPT ); Mon, 22 Feb 2016 11:37:03 -0500 Received: by mail-qk0-f178.google.com with SMTP id x1so57653790qkc.1; Mon, 22 Feb 2016 08:37:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=XZyAQUkBiChigGXblOpzboky6DzW1cYLEslBumwN3vY=; b=RD4KeQ1YZ+WmgZKXcbhz7rHBRMUeIcuj9kfF7jm+5d5p+i9VvJhVAgqFNt5CG4n2L5 zKwamk3Evb+GzQats3VdhZK11VvdKC72c/tti3zd36WHV+v/M0SI27SOv3XDNGdg1WH6 1CmePgPc6JG1/7eED6e/V/WVPdPPyyK3lPlpRTTgPOMWarc+RykXqT+w8XqMk5OPt4J2 GSVC8eAUkg+6CEK7S47v7yzZeZSzgyj6fskVWf95dfgY0zsh4I1IJ4bQrkk3WJVHn6Fn sIZPLmeit7a2btcBbFmLDquV9VLsOSpjRpo82sZMfz/uk6FWagxdwqjZSs9mRfFhigQM NLZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=XZyAQUkBiChigGXblOpzboky6DzW1cYLEslBumwN3vY=; b=d7oVp0s+ZKpVvfBpINWF1fzGswW0mRm0/m4zjYsKCA/28B9VyfVT8NbXO2pYaFXckk covOGQ+RJMEhryovGPQasF90XFZi+XfNVV/AKPfiAuihX3dUluvslVJqF+xOyc23x/0F GRY7E+ggDjdX9+uli87ojYNHZR4J5/+GdwLOlM0kfPxTqe6aDnQq9k/BPkdgbMCQSsEs JPfUXfKGJrrMYqJ5EWQlo9ZfLHCqwol2DY55tD/mw+B155JI/3o5FsRmpoKNRpUOhxVJ rAMgxzTgOkT07dcJysHc2D3cqZsO67G7yiB13uCcFTf8tnob0RYPZWRYxRAE5/DUsibC L2tw== X-Gm-Message-State: AG10YORyAiHZmzjmsK7FVR5fnf5BRUFtgwd0mYTU2LsmTDZvLkUnOEtTkoC0Xv2GHtwQGA== X-Received: by 10.55.73.74 with SMTP id w71mr36200054qka.60.1456159022247; Mon, 22 Feb 2016 08:37:02 -0800 (PST) Received: from kiddo.endlessm-sf.com (c-98-239-150-235.hsd1.wv.comcast.net. [98.239.150.235]) by smtp.gmail.com with ESMTPSA id j67sm6874669qgj.35.2016.02.22.08.37.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 08:37:01 -0800 (PST) From: "=?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?=" X-Google-Original-From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= To: Johannes Berg Cc: "David S. Miller" , Darren Hart , 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, =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= Subject: [PATCHv2 05/10] rfkill: Factor rfkill_global_states[].cur assignments Date: Mon, 22 Feb 2016 11:36:36 -0500 Message-Id: <1456159001-20307-6-git-send-email-jprvita@endlessm.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456159001-20307-1-git-send-email-jprvita@endlessm.com> References: <1456159001-20307-1-git-send-email-jprvita@endlessm.com> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Factor all assignments to rfkill_global_states[].cur into a single function rfkill_update_global_state(). Signed-off-by: João Paulo Rechi Vita --- 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)