From patchwork Tue Jan 19 15:42:38 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: 8063401 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 DACC0BEEE5 for ; Tue, 19 Jan 2016 15:45:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F55A2039E for ; Tue, 19 Jan 2016 15:45:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 70753203A1 for ; Tue, 19 Jan 2016 15:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756683AbcASPo0 (ORCPT ); Tue, 19 Jan 2016 10:44:26 -0500 Received: from mail-qk0-f193.google.com ([209.85.220.193]:34484 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755861AbcASPoG (ORCPT ); Tue, 19 Jan 2016 10:44:06 -0500 Received: by mail-qk0-f193.google.com with SMTP id u128so2726482qkh.1; Tue, 19 Jan 2016 07:44:06 -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=bBm8/oA8k8ck+Wa7MnQQRveBsmzYELNjUt8wpHfBF6o=; b=fEEgvvVIWjdY+GqSjkGUTc7SVbbQaTEpnozzz1AxiApeH6UDNuMyJfp6yD94sr0gsT 9lfYWkZEpBHtM53Amb/U7BZ68w8q5phYTQ5LhO9Z+wPXBhs4nwpJlZK2hplSvX1jdwmI euNMyF8YjZg4stHgBCiUz5G5/M0XH80JT8eUGUkInit5GLa2OWPluOAcs5XqR+TIdl2M V6AXuf77zMrVsx9MMYc+EX6BxOcDUGf5gkg9OX91x2bXURE2ypE4TkHt4uP3U1aOI1Ij UX6Q/ekqoyEKQ06JYJSLOBuzD6Gxc7VQRlWhId+YFpqMFMy1P/ZvulYwwvxg0CS/Xc55 Hlcg== 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=bBm8/oA8k8ck+Wa7MnQQRveBsmzYELNjUt8wpHfBF6o=; b=QXFMWOKFZvMYbfPisPQX+7/qUCwfnVtM/fI7/FZoQbVS72jkFZxdSkwZavhVl953gv MwpleV6fAJPW9YFweJofiEZmI/JS96GjEaIXmA7HhkV7sJZCaUP/0Kk3sEwHFLIKvKXM C4U680hr+Z/S7WZNsqd5Fasc4l6pjUDww/FdlAUsPENJlx8KjqlavqE5MU8xUr1pMIdu XHMFqgMz2cWwkjYrRAow7PLHjKp4p/SGhZ+ihGMLsvOEPGI+neaF8y1y2YfGrynZK88z zwfFPw71gE+FXjxdzVvmKLcmtsItQy3WG15m1570N+pdmKlAIi6YSe2l9bQpQ+WlOpi/ Csng== X-Gm-Message-State: ALoCoQn1468FyILYuMPZULG59Q31Mldk1WaCpSEqDYn5R/FXg2Sa4miDh71LqggU26xFfAoGG2WwyfgxX0uhntezZO4XqW9g/g== X-Received: by 10.55.15.139 with SMTP id 11mr38487080qkp.50.1453218245832; Tue, 19 Jan 2016 07:44:05 -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.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Jan 2016 07:44:05 -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 3/8] rfkill: Improve code readability Date: Tue, 19 Jan 2016 10:42:38 -0500 Message-Id: <1453218163-31998-4-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 __rfkill_set_hw_state() is only one used in rfkill_set_hw_state(), and none of them are long or complicated, so merging the two makes the code easier to read. Signed-off-by: João Paulo Rechi Vita --- net/rfkill/core.c | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/net/rfkill/core.c b/net/rfkill/core.c index 838e869..5406c76 100644 --- a/net/rfkill/core.c +++ b/net/rfkill/core.c @@ -233,29 +233,6 @@ static void rfkill_event(struct rfkill *rfkill) rfkill_send_events(rfkill, RFKILL_OP_CHANGE); } -static bool __rfkill_set_hw_state(struct rfkill *rfkill, - bool blocked, bool *change) -{ - unsigned long flags; - bool prev, any; - - BUG_ON(!rfkill); - - spin_lock_irqsave(&rfkill->lock, flags); - prev = !!(rfkill->state & RFKILL_BLOCK_HW); - if (blocked) - rfkill->state |= RFKILL_BLOCK_HW; - else - rfkill->state &= ~RFKILL_BLOCK_HW; - *change = prev != blocked; - any = !!(rfkill->state & RFKILL_BLOCK_ANY); - spin_unlock_irqrestore(&rfkill->lock, flags); - - rfkill_led_trigger_event(rfkill); - - return any; -} - /** * rfkill_set_block - wrapper for set_block method * @@ -479,14 +456,26 @@ bool rfkill_get_global_sw_state(const enum rfkill_type type) bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked) { - bool ret, change; + unsigned long flags; + bool ret, prev; + + BUG_ON(!rfkill); + + spin_lock_irqsave(&rfkill->lock, flags); + prev = !!(rfkill->state & RFKILL_BLOCK_HW); + if (blocked) + rfkill->state |= RFKILL_BLOCK_HW; + else + rfkill->state &= ~RFKILL_BLOCK_HW; + ret = !!(rfkill->state & RFKILL_BLOCK_ANY); + spin_unlock_irqrestore(&rfkill->lock, flags); - ret = __rfkill_set_hw_state(rfkill, blocked, &change); + rfkill_led_trigger_event(rfkill); if (!rfkill->registered) return ret; - if (change) + if (prev != blocked) schedule_work(&rfkill->uevent_work); return ret;