mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Wagner <wagi@monom.org>
To: linux-kernel@vger.kernel.org
Cc: Ming Lei <ming.lei@canonical.com>,
	"Luis R . Rodriguez" <mcgrof@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Srivatsa S . Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
	"Rafael J . Wysocki" <rjw@sisk.pl>,
	Daniel Vetter <daniel.vetter@intel.com>,
	Takashi Iwai <tiwai@suse.com>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Arend van Spriel <arend.vanspriel@broadcom.com>,
	Daniel Wagner <daniel.wagner@bmw-carit.de>
Subject: [PATCH v6 4/6] firmware: drop bit ops in favor of simple state machine
Date: Thu, 20 Oct 2016 11:52:10 +0200	[thread overview]
Message-ID: <1476957132-27818-5-git-send-email-wagi@monom.org> (raw)
In-Reply-To: <1476957132-27818-1-git-send-email-wagi@monom.org>

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

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 <daniel.wagner@bmw-carit.de>
Cc: Ming Lei <ming.lei@canonical.com>
Cc: Luis R. Rodriguez <mcgrof@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 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

  parent reply	other threads:[~2016-10-20  9:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-20  9:52 [PATCH v6 0/6] firmware: encapsulate firmware loading status Daniel Wagner
2016-10-20  9:52 ` [PATCH v6 1/6] firmware: move umh locking code into fw_load_from_user_helper() Daniel Wagner
2016-11-09 21:17   ` Luis R. Rodriguez
2016-10-20  9:52 ` [PATCH v6 2/6] firmware: encapsulate firmware loading status Daniel Wagner
2016-10-20  9:52 ` [PATCH v6 3/6] firmware: rename fw_load_from_user_helper() and _request_firmware_load() Daniel Wagner
2016-10-20  9:52 ` Daniel Wagner [this message]
2016-10-20  9:52 ` [PATCH v6 5/6] firmware: do not use fw_lock for fw_state protection Daniel Wagner
2016-10-20  9:52 ` [PATCH v6 6/6] firmware: move fw_state_is_{aborted|done}() into UHM section Daniel Wagner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476957132-27818-5-git-send-email-wagi@monom.org \
    --to=wagi@monom.org \
    --cc=arend.vanspriel@broadcom.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=daniel.vetter@intel.com \
    --cc=daniel.wagner@bmw-carit.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=ming.lei@canonical.com \
    --cc=rjw@sisk.pl \
    --cc=srivatsa.bhat@linux.vnet.ibm.com \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®