From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755997AbbIUF01 (ORCPT ); Mon, 21 Sep 2015 01:26:27 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:32833 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752419AbbIUF00 (ORCPT ); Mon, 21 Sep 2015 01:26:26 -0400 Date: Sun, 20 Sep 2015 22:26:25 -0700 From: Greg KH To: "K. Y. Srinivasan" Cc: linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com Subject: Re: [PATCH 4/5] hv: kvp: use wrappers to propaigate state Message-ID: <20150921052625.GB24350@kroah.com> References: <1442363823-22428-1-git-send-email-kys@microsoft.com> <1442363874-22508-1-git-send-email-kys@microsoft.com> <1442363874-22508-4-git-send-email-kys@microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1442363874-22508-4-git-send-email-kys@microsoft.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 15, 2015 at 05:37:53PM -0700, K. Y. Srinivasan wrote: > From: Olaf Hering > > The "state" is used by several threads of execution. > Propagate the state to make changes visible. Also propagate context > change in kvp_on_msg. > > Signed-off-by: Olaf Hering > Signed-off-by: K. Y. Srinivasan > --- > drivers/hv/hv_kvp.c | 39 +++++++++++++++++++++------------------ > 1 files changed, 21 insertions(+), 18 deletions(-) > > diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c > index 74c38a9..778d353 100644 > --- a/drivers/hv/hv_kvp.c > +++ b/drivers/hv/hv_kvp.c > @@ -61,7 +61,7 @@ > */ > > static struct { > - int state; /* hvutil_device_state */ > + enum hvutil_device_state state; > int recv_len; /* number of bytes received. */ > struct hv_kvp_msg *kvp_msg; /* current message */ > struct vmbus_channel *recv_channel; /* chn we got the request */ > @@ -74,6 +74,9 @@ static struct { > */ > static int dm_reg_value; > > +#define kvp_get_state() hvutil_device_get_state(&kvp_transaction.state) > +#define kvp_set_state(s) hvutil_device_set_state(&kvp_transaction.state, s) > + > static void kvp_send_key(struct work_struct *dummy); > > > @@ -122,8 +125,8 @@ static void kvp_timeout_func(struct work_struct *dummy) > kvp_respond_to_host(NULL, HV_E_FAIL); > > /* Transaction is finished, reset the state. */ > - if (kvp_transaction.state > HVUTIL_READY) > - kvp_transaction.state = HVUTIL_READY; > + if (kvp_get_state() > HVUTIL_READY) > + kvp_set_state(HVUTIL_READY); > And what if the state changed the line after this? Oops, your code is hosed. See, you need a lock, do this correctly. greg k-h