Skip to content

Commit 0430caf

Browse files
Daniel Wagnergregkh
Daniel Wagner
authored andcommitted
firmware: drop bit ops in favor of simple state machine
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. Cc: Ming Lei <[email protected]> Signed-off-by: Daniel Wagner <[email protected]> Acked-by: Luis R. Rodriguez <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f52cc37 commit 0430caf

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

drivers/base/firmware_class.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static inline long firmware_loading_timeout(void)
112112
*/
113113
struct fw_state {
114114
struct completion completion;
115-
unsigned long status;
115+
enum fw_status status;
116116
};
117117

118118
static void fw_state_init(struct fw_state *fw_st)
@@ -123,7 +123,7 @@ static void fw_state_init(struct fw_state *fw_st)
123123

124124
static int __fw_state_check(struct fw_state *fw_st, enum fw_status status)
125125
{
126-
return test_bit(status, &fw_st->status);
126+
return fw_st->status == status;
127127
}
128128

129129
static long __fw_state_wait_common(struct fw_state *fw_st, long timeout)
@@ -132,7 +132,7 @@ static long __fw_state_wait_common(struct fw_state *fw_st, long timeout)
132132

133133
ret = wait_for_completion_interruptible_timeout(&fw_st->completion,
134134
timeout);
135-
if (ret != 0 && test_bit(FW_STATUS_ABORTED, &fw_st->status))
135+
if (ret != 0 && READ_ONCE(fw_st->status) == FW_STATUS_ABORTED)
136136
return -ENOENT;
137137

138138
return ret;
@@ -141,12 +141,10 @@ static long __fw_state_wait_common(struct fw_state *fw_st, long timeout)
141141
static void __fw_state_set(struct fw_state *fw_st,
142142
enum fw_status status)
143143
{
144-
set_bit(status, &fw_st->status);
144+
WRITE_ONCE(fw_st->status, status);
145145

146-
if (status == FW_STATUS_DONE || status == FW_STATUS_ABORTED) {
147-
clear_bit(FW_STATUS_LOADING, &fw_st->status);
146+
if (status == FW_STATUS_DONE || status == FW_STATUS_ABORTED)
148147
complete_all(&fw_st->completion);
149-
}
150148
}
151149

152150
#define fw_state_start(fw_st) \

0 commit comments

Comments
 (0)