lkml.org 
[lkml]   [2016]   [Sep]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [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@bmw-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@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;

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

\
 
 \ /
  Last update: 2016-09-17 09:59    [W:0.097 / U:1.364 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site