From: Daniel Wagner <daniel.wag...@bmw-carit.de>

We track the state of the loading with bit ops. Since the state machine
has only a couple of states and they are all mutual exclusive there are
only a few simple state transition we can model this simplify.

           UNKNOWN -> LOADING -> DONE | ABORTED

Cc: Ming Lei <ming....@canonical.com>
Cc: Luis R. Rodriguez <mcg...@kernel.org>
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org>
Signed-off-by: Daniel Wagner <daniel.wag...@bmw-carit.de>
---
 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 5e38c27..8f5838c 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -109,7 +109,7 @@ enum {
 
 struct fw_umh {
        struct completion completion;
-       unsigned long status;
+       u8 status;
 };
 
 static void fw_umh_init(struct fw_umh *fw_umh)
@@ -120,7 +120,7 @@ static void fw_umh_init(struct fw_umh *fw_umh)
 
 static int __fw_umh_check(struct fw_umh *fw_umh, unsigned long status)
 {
-       return test_bit(status, &fw_umh->status);
+       return fw_umh->status == status;
 }
 
 static int fw_umh_wait_timeout(struct fw_umh *fw_umh, long timeout)
@@ -129,7 +129,7 @@ static int fw_umh_wait_timeout(struct fw_umh *fw_umh, long 
timeout)
 
        ret = wait_for_completion_interruptible_timeout(&fw_umh->completion,
                                                        timeout);
-       if (ret != 0 && test_bit(FW_UMH_ABORTED, &fw_umh->status))
+       if (ret != 0 && READ_ONCE(fw_umh->status) == FW_UMH_ABORTED)
                return -ENOENT;
 
        return ret;
@@ -138,12 +138,10 @@ static int fw_umh_wait_timeout(struct fw_umh *fw_umh, 
long timeout)
 static void __fw_umh_set(struct fw_umh *fw_umh,
                          unsigned long status)
 {
-       set_bit(status, &fw_umh->status);
+       WRITE_ONCE(fw_umh->status, status);
 
-       if (status == FW_UMH_DONE || status == FW_UMH_ABORTED) {
-               clear_bit(FW_UMH_LOADING, &fw_umh->status);
+       if (status == FW_UMH_DONE || status == FW_UMH_ABORTED)
                complete_all(&fw_umh->completion);
-       }
 }
 
 #define fw_umh_start(fw_umh)                                   \
-- 
2.7.4

Reply via email to