Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1480421

Re: [PATCH v5 4/5] firmware: drop bit ops in favor of simple state machine

From "Luis R. Rodriguez" <mcgrof@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH v5 4/5] firmware: drop bit ops in favor of simple state machine
Date 2016-09-10 00:40 +0200
Message-ID <sfCCJ-mH-27@gated-at.bofh.it> (permalink)
References <sfsWJ-2Il-1@gated-at.bofh.it> <sfsWK-2Il-27@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v5 0/5] firmware: encapsulate firmware loading status Daniel Wagner <wagi@monom.org> - 2016-09-09 14:20 +0200
  [PATCH v5 3/5] firmware: rename fw_load_from_user_helper() and _request_firmware_load() Daniel Wagner <wagi@monom.org> - 2016-09-09 14:20 +0200
    Re: [PATCH v5 3/5] firmware: rename fw_load_from_user_helper() and  _request_firmware_load() "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-09-10 00:20 +0200
  [PATCH v5 1/5] firmware: document user mode helper lock usage Daniel Wagner <wagi@monom.org> - 2016-09-09 14:20 +0200
    Re: [PATCH v5 1/5] firmware: document user mode helper lock usage "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-09-10 00:20 +0200
      Re: [PATCH v5 1/5] firmware: document user mode helper lock usage Ming Lei <ming.lei@canonical.com> - 2016-09-22 04:40 +0200
  [PATCH v5 4/5] firmware: drop bit ops in favor of simple state machine Daniel Wagner <wagi@monom.org> - 2016-09-09 14:20 +0200
    Re: [PATCH v5 4/5] firmware: drop bit ops in favor of simple state  machine "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-09-10 00:40 +0200
  [PATCH v5 2/5] firmware: encapsulate firmware loading status Daniel Wagner <wagi@monom.org> - 2016-09-09 14:20 +0200
    Re: [PATCH v5 2/5] firmware: encapsulate firmware loading status "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-09-10 00:20 +0200
    Re: [PATCH v5 2/5] firmware: encapsulate firmware loading status "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-09-10 00:30 +0200
    Re: [PATCH v5 2/5] firmware: encapsulate firmware loading status Daniel Wagner <daniel.wagner@bmw-carit.de> - 2016-09-13 11:50 +0200
  [PATCH v5 5/5] firmware: do not use fw_lock for fw_umh protection Daniel Wagner <wagi@monom.org> - 2016-09-09 14:20 +0200
  Re: [PATCH v5 0/5] firmware: encapsulate firmware loading status "Luis R. Rodriguez" <mcgrof@kernel.org> - 2016-09-09 19:40 +0200

csiph-web