From patchwork Mon Feb 8 15:41:32 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: 8251511 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 A420E9F3CD for ; Mon, 8 Feb 2016 15:47:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C08FC203B7 for ; Mon, 8 Feb 2016 15:47:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC8D0202EC for ; Mon, 8 Feb 2016 15:47:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932116AbcBHPo0 (ORCPT ); Mon, 8 Feb 2016 10:44:26 -0500 Received: from mail-qg0-f67.google.com ([209.85.192.67]:32879 "EHLO mail-qg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754932AbcBHPlp (ORCPT ); Mon, 8 Feb 2016 10:41:45 -0500 Received: by mail-qg0-f67.google.com with SMTP id y89so4006176qge.0; Mon, 08 Feb 2016 07:41:45 -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=c9BwewvHgvNyeMYxfWBsq+vyaNPJ8fWDTkyBl+1ZpaHyXm1tXMSDlx7QIE0fQcj88v FhLc9wKT+HPcHzz4shLSAY55VbqGvm7js2CZGz4ZiX7HS9Dp6zdRu/ZzxHi+CqcqAZLY kUdvCgwPVnEok2+VmU4G9mRwbXNwcUMxhL82tLiZRoRxWRYXOnDJ9r4hLOChOkfpvo96 KYwB1XhTC+GLmO9hI9PIdA6ZaKYpfXtqbgFal806DeK9Wc/WFMKXkuxeraVqdXO3cl/g TAsdVL0aKa+s3+6gTJXPd1hIuoOEx8VCNjNICQgscpt2t2JAi4K89P5H0bkCfUwWmHut qoOg== 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=FMcWTdqV0nHn2/R7tqeD1HU7wyrOSAOSI0RjAbzdnZbC/oZeUKbGq3q4qMYuI9rlih 7h+nbBIrdaCCVNvoDk9xW48TJJdWMdtPvmnAcPeradEfQNlyBxnC+lXvUVpwNGjjJvA1 1Ww2Q3TQ4VlgCWbIqG3aHN7kaIkC+Iut5IiNGnLM3h0fIzK7ra4YCl22ghrjerFRoLW7 Bj9ZrcsDx6v99owNGdmB2K3aOPUQR760yVaaDeq/uzMTkkzXYKEfhiRje9w6GRATrAi7 dgx3Kx2Jw9rJ4/6lUjkFFmC5iJfHBfssgjdgpH4gsEpuoIIqoXxSuBxbaxRNoLA4j1kr 3CSw== X-Gm-Message-State: AG10YOSRFIEjN152M3fS9cenP/y3V8aCgHVB5j6YvY7jHqurlMZ/hH3ZOtTlsRSNW54Kug== X-Received: by 10.140.252.197 with SMTP id x188mr36878469qhc.81.1454946104818; Mon, 08 Feb 2016 07:41:44 -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 p188sm14000390qhb.34.2016.02.08.07.41.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Feb 2016 07:41:44 -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: [PATCH 5/9] rfkill: Factor rfkill_global_states[].cur assignments Date: Mon, 8 Feb 2016 10:41:32 -0500 Message-Id: <1454946096-9752-6-git-send-email-jprvita@endlessm.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1454946096-9752-1-git-send-email-jprvita@endlessm.com> References: <1454946096-9752-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=-7.1 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 Reviewed-by: Julian Calaby --- 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)