From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755107AbcIIWaJ (ORCPT ); Fri, 9 Sep 2016 18:30:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:57798 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753520AbcIIWaH (ORCPT ); Fri, 9 Sep 2016 18:30:07 -0400 Date: Sat, 10 Sep 2016 00:30:04 +0200 From: "Luis R. Rodriguez" To: Daniel Wagner Cc: linux-kernel@vger.kernel.org, Ming Lei , "Luis R . Rodriguez" , Greg Kroah-Hartman , "rafael.j.wysocki" , Daniel Vetter , Takashi Iwai , Bjorn Andersson , Arend van Spriel , Daniel Wagner Subject: Re: [PATCH v5 4/5] firmware: drop bit ops in favor of simple state machine Message-ID: <20160909223004.GS3296@wotan.suse.de> References: <1473423144-21734-1-git-send-email-wagi@monom.org> <1473423144-21734-5-git-send-email-wagi@monom.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1473423144-21734-5-git-send-email-wagi@monom.org> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 09, 2016 at 02:12:23PM +0200, Daniel Wagner wrote: > From: Daniel Wagner > > 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 > Cc: Luis R. Rodriguez > Cc: Greg Kroah-Hartman > Signed-off-by: Daniel Wagner > --- > 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