lkml.org 
[lkml]   [2016]   [Sep]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH v5 4/5] firmware: drop bit ops in favor of simple state machine
    Date
    From: Daniel Wagner <daniel.wagner@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.lei@canonical.com>
    Cc: Luis R. Rodriguez <mcgrof@kernel.org>
    Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: Daniel Wagner <daniel.wagner@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
    \
     
     \ /
      Last update: 2016-09-17 09:59    [W:4.111 / U:1.340 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site