Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934132AbcJTJwb (ORCPT ); Thu, 20 Oct 2016 05:52:31 -0400 Received: from atlantic540.startdedicated.de ([188.138.9.77]:46995 "EHLO atlantic540.startdedicated.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933668AbcJTJw2 (ORCPT ); Thu, 20 Oct 2016 05:52:28 -0400 From: Daniel Wagner To: linux-kernel@vger.kernel.org Cc: Ming Lei , "Luis R . Rodriguez" , Greg Kroah-Hartman , "Srivatsa S . Bhat" , "Rafael J . Wysocki" , Daniel Vetter , Takashi Iwai , Bjorn Andersson , Arend van Spriel , Daniel Wagner Subject: [PATCH v6 4/6] firmware: drop bit ops in favor of simple state machine Date: Thu, 20 Oct 2016 11:52:10 +0200 Message-Id: <1476957132-27818-5-git-send-email-wagi@monom.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1476957132-27818-1-git-send-email-wagi@monom.org> References: <1476957132-27818-1-git-send-email-wagi@monom.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2488 Lines: 72 From: Daniel Wagner We track the state of the firmware loading with bit ops. Since the state machine has only a few states and they are all mutual exclusive there are only a few simple state transition we can model this simplify. UNKNOWN -> LOADING -> DONE | ABORTED Because we don't use any bit ops on fw_state::status anymore we are able to change the data type to enum fw_status and update the function arguments accordingly. READ_ONCE() and WRITE_ONCE() are propably not needed because there are a lot of load and stores around fw_st->status. But let's make it explicit and not be sorry later. Signed-off-by: Daniel Wagner Cc: Ming Lei Cc: Luis R. Rodriguez Cc: Greg Kroah-Hartman --- drivers/base/firmware_class.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index a6916a7aaeb2..a1dab6a792f1 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c @@ -106,7 +106,7 @@ enum fw_status { */ struct fw_state { struct completion completion; - unsigned long status; + enum fw_status status; }; static void fw_state_init(struct fw_state *fw_st) @@ -117,7 +117,7 @@ static void fw_state_init(struct fw_state *fw_st) static int __fw_state_check(struct fw_state *fw_st, enum fw_status status) { - return test_bit(status, &fw_st->status); + return fw_st->status == status; } static int __fw_state_wait_common(struct fw_state *fw_st, long timeout) @@ -126,7 +126,7 @@ static int __fw_state_wait_common(struct fw_state *fw_st, long timeout) ret = wait_for_completion_interruptible_timeout(&fw_st->completion, timeout); - if (ret != 0 && test_bit(FW_STATUS_ABORTED, &fw_st->status)) + if (ret != 0 && READ_ONCE(fw_st->status) == FW_STATUS_ABORTED) return -ENOENT; return ret; @@ -135,12 +135,10 @@ static int __fw_state_wait_common(struct fw_state *fw_st, long timeout) static void __fw_state_set(struct fw_state *fw_st, enum fw_status status) { - set_bit(status, &fw_st->status); + WRITE_ONCE(fw_st->status, status); - if (status == FW_STATUS_DONE || status == FW_STATUS_ABORTED) { - clear_bit(FW_STATUS_LOADING, &fw_st->status); + if (status == FW_STATUS_DONE || status == FW_STATUS_ABORTED) complete_all(&fw_st->completion); - } } #define fw_state_start(fw_st) \ -- 2.7.4