Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751650AbcCHWz6 (ORCPT ); Tue, 8 Mar 2016 17:55:58 -0500 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:47469 "EHLO e23smtp09.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750981AbcCHWzw (ORCPT ); Tue, 8 Mar 2016 17:55:52 -0500 X-IBM-Helo: d23dlp01.au.ibm.com X-IBM-MailFrom: honclo@linux.vnet.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org Subject: Re: [PATCH] vTPM: fix missing error handling for suspend operation From: "Hon Ching(Vicky) Lo" To: Jarkko Sakkinen Cc: tpmdd-devel@lists.sourceforge.net, Peter Huewe , Ashley Lai , Vicky Lo , linux-kernel@vger.kernel.org In-Reply-To: <1457469855.30806.14.camel@vtpm2014.ibm.com> References: <1456899827-14365-1-git-send-email-honclo@linux.vnet.ibm.com> <20160304165537.GA13204@intel.com> <1457469855.30806.14.camel@vtpm2014.ibm.com> Content-Type: text/plain; charset="UTF-8" Date: Tue, 08 Mar 2016 17:54:38 -0500 Message-ID: <1457477678.800.7.camel@vtpm2014.ibm.com> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-34.el6) Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16030822-0033-0000-0000-0000031E5D3D Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1976 Lines: 61 > > > + } else if (crq.msg == (u8) PARTNER_PARTITION_FAILED) { > > > + dev_err(ibmvtpm->dev, > > > + "vtpm has terminated fatally; reboot to reinstate a trusted state.\n"); > > > + } else if (crq.msg == (u8) PARTNER_PARTITION_DEREG_CRQ) { > > > + /* The vtpm is in the process of being reloaded by > > > + * firmware and has de-registered CRQ. The client > > > + * must wait for the CRQ INITIALIZATION message and > > > + * respond and must resubmit suspend message. > > > + */ > > > + sig = > > > + wait_event_interruptible(ibmvtpm->wq, > > > + crq_initialized == 1); > > > + if (sig) > > > + return -EINTR; > > > + > > > + if (suspend_again_count < 1) { > > > + suspend_again_count++; > > > + goto suspendagain; > > > + } > > > + } else > > > + ; > > > + } > > > + > > > if (rc != H_SUCCESS) > > > - dev_err(ibmvtpm->dev, > > > - "tpm_ibmvtpm_suspend failed rc=%d\n", rc); > > > + dev_err(ibmvtpm->dev, "tpm_ibmvtpm_suspend failed rc=%d\n", rc); > > > > > > return rc; > > > + > > > +suspendagain: > > > + rc = tpm_ibmvtpm_suspend(ibmvtpm->dev); > > > + suspend_again_count = 0; > > > + > > > + if (rc != H_SUCCESS) > > > + dev_err(ibmvtpm->dev, "tpm_ibmvtpm_suspend failed rc=%d\n", rc); > > > + > > > + return rc; > > > + > > > > Get rid of this horrible looking tail recursion thing. > > > > What the heck is suspend_again_count and why it can be module scope > > variable? You could use a local variable instead if you would iterate > > with a loop. > > > > /Jarkko > > > > The reason for the 'goto' statement and the suspend_again_count was to > prevent the suspend function recurse again. In the case if vtpm is in > the process of being reloaded by firmware, we want to wait for the CRQ > INITIALIZATION and resubmit suspend message i.e. recurse only once. > Never mind.. I don't really save any repetitive code by using recursion now. I'll rework and resubmit the patch. Thanks, Vicky