[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Sat, 10 Sep 2016 00:30:04 +0200
From: "Luis R. Rodriguez" <mcgrof@...nel.org>
To: Daniel Wagner <wagi@...om.org>
Cc: linux-kernel@...r.kernel.org, Ming Lei <ming.lei@...onical.com>,
"Luis R . Rodriguez" <mcgrof@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"rafael.j.wysocki" <rafael.j.wysocki@...el.com>,
Daniel Vetter <daniel.vetter@...el.com>,
Takashi Iwai <tiwai@...e.com>,
Bjorn Andersson <bjorn.andersson@...aro.org>,
Arend van Spriel <arend.vanspriel@...adcom.com>,
Daniel Wagner <daniel.wagner@...-carit.de>
Subject: Re: [PATCH v5 4/5] firmware: drop bit ops in favor of simple state
machine
On Fri, Sep 09, 2016 at 02:12:23PM +0200, Daniel Wagner wrote:
> From: Daniel Wagner <daniel.wagner@...-carit.de>
>
> We track the state of the loading with bit ops. Since the state machine
We track the state of the firmware usermode helper loading with bit ops.
> 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
If you also do the change suggested below you'd have to annotate that change in the
commit log as well.
>
> Cc: Ming Lei <ming.lei@...onical.com>
> Cc: Luis R. Rodriguez <mcgrof@...nel.org>
> Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> Signed-off-by: Daniel Wagner <daniel.wagner@...-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;
Sorry I know I suggested the u8 but below you end up still using unsigned long status.
Instead of fixing this please consider changing:
struct fw_umh {
struct completion completion;
- unsigned long status;
+ enum fw_umh_status status;
Then you can use the enum fw_umh_status status in function arguments, I've used this
trick in other codebases to ensure that the data type for the status passed then
matches the same one expected, *and* if you use a switch() statement the compiler
will complain and moan about missing values (unless a default switch statement
is present). For such simple state machines then this is better practice.
> };
>
> 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;
Why does this not use READ_ONCE(fw_umh->status) ?
Luis
Powered by blists - more mailing lists