From patchwork Tue Jan 19 15:42:43 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: 8063431 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 688749F859 for ; Tue, 19 Jan 2016 15:45:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 91631203AC for ; Tue, 19 Jan 2016 15:45:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34EEA203AA for ; Tue, 19 Jan 2016 15:45:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756866AbcASPp0 (ORCPT ); Tue, 19 Jan 2016 10:45:26 -0500 Received: from mail-qg0-f66.google.com ([209.85.192.66]:34200 "EHLO mail-qg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756429AbcASPoK (ORCPT ); Tue, 19 Jan 2016 10:44:10 -0500 Received: by mail-qg0-f66.google.com with SMTP id 94so65239981qgt.1; Tue, 19 Jan 2016 07:44:10 -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=sL+X7YOJz3X0grLUXTXPwVlAnqnf0UhOmYBObkzybUM=; b=Cow4397N88YOd+wWVsHmdQYdr/3V00DBuptz18ZMC/djsZKm5iJabmS6RQMm7taNsp sDkPL13vYx5LIhdFyLR87aQ8Rso0U5t4cqgMERSOvrZS2zM+hj/fLpTxqNZVJXycLR/e +CoJv/mwCRWWckYhiBDU2OEOccdcCChzNe7H9IoPxC2J9wHTu73bVtkNJoLVOuhVg7PT SaCR/ptHADYyGYj7zORmQZ2A73dkfe9Y6AtZ+SvrMQ7WZUoYv380RrMM2E0mOOPMkd6f 5jS+IPCBz0Fr151cq1pY1Eg4otbewrBgafieAZ/2lbuANMfZmosS3gzzDWtst66Ef+GP MGrA== 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=sL+X7YOJz3X0grLUXTXPwVlAnqnf0UhOmYBObkzybUM=; b=Fk85/9Q11Ki62cRWz5sN0jPu2DMPuQHAxrv89KxXRroHyX31+MPMTt2LkqR+iLNcHo 8zJ4LJy3+Rykga9A3B14WhXCPCgwEDAr5ZC3V7mm+wlOynR2JXRWXxevqRxQDmbEyP4c AeRSV2RvzcRZ43KcIPHnTAICr8dRSqxvUbi9moREgSsg+MzItv87FaoB6aaR0Bg+MurI 6s+QMhwoHBSxLqdCJiH3pMCejoz3Y0tm57KH387g2bgOGx6A1Ra0cAT18tHqhwSkBZQp RwCldn8Ik8eeFNAkDi/FWSTy4Ba1+wu5/HXoBM53TOBc0bleWVHdIJn0E5Jv/WQ7uls2 jxUg== X-Gm-Message-State: ALoCoQnGGgCRmaZFeNXDLxrRI/kAVpznIRs4HNDI4hCjQdhgD8D15+D29yXSEPFgQGgBiF/3rtwoQ0LKh895iWCSh8IgA9cN9w== X-Received: by 10.140.43.116 with SMTP id d107mr38356691qga.51.1453218249766; Tue, 19 Jan 2016 07:44:09 -0800 (PST) Received: from localhost.localdomain (c-98-239-150-235.hsd1.wv.comcast.net. [98.239.150.235]) by smtp.gmail.com with ESMTPSA id z10sm12336759qhz.5.2016.01.19.07.44.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Jan 2016 07:44:09 -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@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 Message-Id: <1453218163-31998-9-git-send-email-jprvita@endlessm.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1453218163-31998-1-git-send-email-jprvita@endlessm.com> References: <1453218163-31998-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=ham 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 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 --- 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)