Linux-Sgx Archive on lore.kernel.org
 help / color / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: linux-sgx@vger.kernel.org
Subject: [PATCH for_v25 2/4] x86/sgx: Use goto to handle sgx_encl_get_backing() failure in SECS flows
Date: Fri, 20 Dec 2019 16:31:54 -0800
Message-ID: <20191221003156.27236-3-sean.j.christopherson@intel.com> (raw)
In-Reply-To: <20191221003156.27236-1-sean.j.christopherson@intel.com>

Use a goto for the SECS backing error path in sgx_reclaimer_write() so
that the happy path is a straight shot, e.g. to make it obvious that the
backing is not being leaked.  Reducing the indentation also eliminates a
line wrap.

No functional change intended.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---

I could go either way on this patch, included it in case you have a
preference.

 arch/x86/kernel/cpu/sgx/reclaim.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/x86/kernel/cpu/sgx/reclaim.c b/arch/x86/kernel/cpu/sgx/reclaim.c
index 67bda5528625..c5c0ba92ab63 100644
--- a/arch/x86/kernel/cpu/sgx/reclaim.c
+++ b/arch/x86/kernel/cpu/sgx/reclaim.c
@@ -355,18 +355,19 @@ static void sgx_reclaimer_write(struct sgx_epc_page *epc_page,
 		} else if (atomic_read(&encl->flags) & SGX_ENCL_INITIALIZED) {
 			ret = sgx_encl_get_backing(encl, PFN_DOWN(encl->size),
 						   &secs_backing);
-			if (!ret) {
-				sgx_encl_ewb(encl->secs.epc_page,
-					     &secs_backing);
+			if (ret)
+				goto out;
 
-				sgx_free_page(encl->secs.epc_page);
-				encl->secs.epc_page = NULL;
+			sgx_encl_ewb(encl->secs.epc_page, &secs_backing);
 
-				sgx_encl_put_backing(&secs_backing, true);
-			}
+			sgx_free_page(encl->secs.epc_page);
+			encl->secs.epc_page = NULL;
+
+			sgx_encl_put_backing(&secs_backing, true);
 		}
 	}
 
+out:
 	mutex_unlock(&encl->lock);
 }
 
-- 
2.24.1


  parent reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-21  0:31 [PATCH for_v25 0/4] x86/sgx: Reclaim bug fix and cleanup Sean Christopherson
2019-12-21  0:31 ` [PATCH for_v25 1/4] x86/sgx: Put SECS backing iff retrieving the backing succeeds Sean Christopherson
2019-12-21  0:31 ` Sean Christopherson [this message]
2019-12-21  0:31 ` [PATCH for_v25 3/4] x86/sgx: Drop unused @encl parameter from __sgx_encl_ewb() Sean Christopherson
2019-12-21  0:31 ` [PATCH for_v25 4/4] x86/sgx: Pre-calculate VA slot virtual address in sgx_encl_ewb() Sean Christopherson
2020-01-02 17:06 ` [PATCH for_v25 0/4] x86/sgx: Reclaim bug fix and cleanup Jarkko Sakkinen

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191221003156.27236-3-sean.j.christopherson@intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=jarkko.sakkinen@linux.intel.com \
    --cc=linux-sgx@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Sgx Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-sgx/0 linux-sgx/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-sgx linux-sgx/ https://lore.kernel.org/linux-sgx \
		linux-sgx@vger.kernel.org
	public-inbox-index linux-sgx

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-sgx


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git