Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0430cafc authored by Daniel Wagner's avatar Daniel Wagner Committed by Greg Kroah-Hartman
Browse files

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 <ming.lei@canonical.com>
Signed-off-by: default avatarDaniel Wagner <daniel.wagner@bmw-carit.de>
Acked-by: default avatarLuis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f52cc379
Loading
Loading
Loading
Loading
+5 −7
Original line number Original line Diff line number Diff line
@@ -112,7 +112,7 @@ static inline long firmware_loading_timeout(void)
 */
 */
struct fw_state {
struct fw_state {
	struct completion completion;
	struct completion completion;
	unsigned long status;
	enum fw_status status;
};
};


static void fw_state_init(struct fw_state *fw_st)
static void fw_state_init(struct fw_state *fw_st)
@@ -123,7 +123,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)
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 long __fw_state_wait_common(struct fw_state *fw_st, long timeout)
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)


	ret = wait_for_completion_interruptible_timeout(&fw_st->completion,
	ret = wait_for_completion_interruptible_timeout(&fw_st->completion,
							timeout);
							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 -ENOENT;


	return ret;
	return ret;
@@ -141,13 +141,11 @@ static long __fw_state_wait_common(struct fw_state *fw_st, long timeout)
static void __fw_state_set(struct fw_state *fw_st,
static void __fw_state_set(struct fw_state *fw_st,
			   enum fw_status status)
			   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) {
	if (status == FW_STATUS_DONE || status == FW_STATUS_ABORTED)
		clear_bit(FW_STATUS_LOADING, &fw_st->status);
		complete_all(&fw_st->completion);
		complete_all(&fw_st->completion);
}
}
}


#define fw_state_start(fw_st)					\
#define fw_state_start(fw_st)					\
	__fw_state_set(fw_st, FW_STATUS_LOADING)
	__fw_state_set(fw_st, FW_STATUS_LOADING)