Blame SOURCES/0003-mok-consolidate-mirroring-code-in-a-helper-instead-o.patch

bf96fb
From 29c11483101b460869a5e0dba1f425073862127d Mon Sep 17 00:00:00 2001
bf96fb
From: Peter Jones <pjones@redhat.com>
bf96fb
Date: Thu, 31 Jan 2019 13:45:30 -0500
bf96fb
Subject: [PATCH 3/3] mok: consolidate mirroring code in a helper instead of
bf96fb
 using goto
bf96fb
bf96fb
There's no reason to complicate the logic with a goto here, instead just
bf96fb
pull the logic we're jumping to out to a helper function.
bf96fb
bf96fb
Signed-off-by: Peter Jones <pjones@redhat.com>
bf96fb
---
bf96fb
 mok.c  | 41 ++++++++++++++++++++++++++++-------------
bf96fb
 shim.h |  2 ++
bf96fb
 2 files changed, 30 insertions(+), 13 deletions(-)
bf96fb
bf96fb
diff --git a/mok.c b/mok.c
bf96fb
index 41925abbb49..2f495e6cf25 100644
bf96fb
--- a/mok.c
bf96fb
+++ b/mok.c
bf96fb
@@ -130,7 +130,8 @@ struct mok_state_variable mok_state_variables[] = {
bf96fb
 	{ NULL, }
bf96fb
 };
bf96fb
 
bf96fb
-static EFI_STATUS mirror_one_mok_variable(struct mok_state_variable *v)
bf96fb
+static EFI_STATUS nonnull(1)
bf96fb
+mirror_one_mok_variable(struct mok_state_variable *v)
bf96fb
 {
bf96fb
 	EFI_STATUS efi_status = EFI_SUCCESS;
bf96fb
 	void *FullData = NULL;
bf96fb
@@ -196,6 +197,29 @@ static EFI_STATUS mirror_one_mok_variable(struct mok_state_variable *v)
bf96fb
 	return efi_status;
bf96fb
 }
bf96fb
 
bf96fb
+/*
bf96fb
+ * Mirror a variable if it has an rtname, and preserve any
bf96fb
+ * EFI_SECURITY_VIOLATION status at the same time.
bf96fb
+ */
bf96fb
+static EFI_STATUS nonnull(1)
bf96fb
+maybe_mirror_one_mok_variable(struct mok_state_variable *v, EFI_STATUS ret)
bf96fb
+{
bf96fb
+	EFI_STATUS efi_status;
bf96fb
+	if (v->rtname) {
bf96fb
+		if (v->flags & MOK_MIRROR_DELETE_FIRST)
bf96fb
+			LibDeleteVariable(v->rtname, v->guid);
bf96fb
+
bf96fb
+		efi_status = mirror_one_mok_variable(v);
bf96fb
+		if (EFI_ERROR(efi_status)) {
bf96fb
+			if (ret != EFI_SECURITY_VIOLATION)
bf96fb
+				ret = efi_status;
bf96fb
+			perror(L"Could not create %s: %r\n", v->rtname,
bf96fb
+			       efi_status);
bf96fb
+		}
bf96fb
+	}
bf96fb
+	return ret;
bf96fb
+}
bf96fb
+
bf96fb
 /*
bf96fb
  * Verify our non-volatile MoK state.  This checks the variables above
bf96fb
  * accessable and have valid attributes.  If they don't, it removes
bf96fb
@@ -232,7 +256,7 @@ EFI_STATUS import_mok_state(EFI_HANDLE image_handle)
bf96fb
 					       *v->guid, &attrs);
bf96fb
 		if (efi_status == EFI_NOT_FOUND) {
bf96fb
 			if (addend)
bf96fb
-				goto mirror_addend;
bf96fb
+				ret = maybe_mirror_one_mok_variable(v, ret);
bf96fb
 			/*
bf96fb
 			 * after possibly adding, we can continue, no
bf96fb
 			 * further checks to be done.
bf96fb
@@ -312,16 +336,8 @@ EFI_STATUS import_mok_state(EFI_HANDLE image_handle)
bf96fb
 			}
bf96fb
 		}
bf96fb
 
bf96fb
-mirror_addend:
bf96fb
-		if (v->rtname && (present || addend)) {
bf96fb
-			if (v->flags & MOK_MIRROR_DELETE_FIRST)
bf96fb
-				LibDeleteVariable(v->rtname, v->guid);
bf96fb
-
bf96fb
-			efi_status = mirror_one_mok_variable(v);
bf96fb
-			if (EFI_ERROR(efi_status) &&
bf96fb
-			    ret != EFI_SECURITY_VIOLATION)
bf96fb
-				ret = efi_status;
bf96fb
-		}
bf96fb
+		if (present)
bf96fb
+			ret = maybe_mirror_one_mok_variable(v, ret);
bf96fb
 	}
bf96fb
 
bf96fb
 	/*
bf96fb
@@ -340,4 +356,4 @@ mirror_addend:
bf96fb
 	return ret;
bf96fb
 }
bf96fb
 
bf96fb
-// vim:fenc=utf-8:tw=75
bf96fb
+// vim:fenc=utf-8:tw=75:noet
bf96fb
diff --git a/shim.h b/shim.h
bf96fb
index 2b359d821e3..c26d5f06538 100644
bf96fb
--- a/shim.h
bf96fb
+++ b/shim.h
bf96fb
@@ -30,6 +30,8 @@
bf96fb
 
bf96fb
 #include <stddef.h>
bf96fb
 
bf96fb
+#define nonnull(...) __attribute__((__nonnull__(__VA_ARGS__)))
bf96fb
+
bf96fb
 #define min(a, b) ({(a) < (b) ? (a) : (b);})
bf96fb
 
bf96fb
 #ifdef __x86_64__
bf96fb
-- 
bf96fb
2.20.1
bf96fb