[v2,11/14] libstb/stb.c: free cvc allocated memory

Message ID 1504164285-15095-12-git-send-email-cclaudio@linux.vnet.ibm.com
State Superseded
Headers show
Series
  • libstb: simplify the initialization of cvc drivers
Related show

Commit Message

Claudio Carvalho Aug. 31, 2017, 7:24 a.m.
We no longer need to hold the cleanup cvc hook because the cvc driver
initialization is now done in a single place.

This adds cvc_free() and also calls it to free the cvc allocated
memory before the skiroot kernel is executed. Additionally, this also
removes the cvc .name attribute.

Signed-off-by: Claudio Carvalho <cclaudio@linux.vnet.ibm.com>
---
 libstb/stb.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

Patch

diff --git a/libstb/stb.c b/libstb/stb.c
index ee5771a..3bc41c6 100644
--- a/libstb/stb.c
+++ b/libstb/stb.c
@@ -33,14 +33,12 @@ 
 //#define STB_DEBUG
 
 struct container_verification_code {
-	const char *name;
 	uint64_t verify_addr;
 	uint64_t sha512_addr;
 	void (*sha512)(void *func_addr, const uint8_t *data, size_t len,
 		       uint8_t *digest);
 	int (*verify)(void *func_addr, const char *name, void *container,
 		      const void *hw_key_hash, size_t hw_key_hash_size);
-	void (*cleanup)(void);
 };
 
 static struct container_verification_code *c1vc = NULL;
@@ -104,6 +102,18 @@  static void sb_enforce(void)
 	abort();
 }
 
+static void cvc_free(void)
+{
+	if (c1vc) {
+		free(c1vc);
+		c1vc = NULL;
+	}
+	if (secure_rom_mem) {
+		free(secure_rom_mem);
+		secure_rom_mem = NULL;
+	}
+}
+
 static int c1vc_mbedtls_init(struct dt_node *node)
 {
 	const char* hash_algo;
@@ -131,8 +141,6 @@  static int c1vc_mbedtls_init(struct dt_node *node)
 	c1vc->sha512 = c1vc_mbedtls_sha512;
 	c1vc->verify_addr = 0;
 	c1vc->verify = c1vc_mbedtls_verify;
-	c1vc->cleanup = c1vc_mbedtls_cleanup;
-	c1vc->name = "c1vc_mbedtls";
 
 	prlog(PR_INFO, "STB: 'ibm,secureboot-v1-softrom' initialized\n");
 	return 0;
@@ -189,9 +197,6 @@  static int c1vc_rom_init(struct dt_node *parent)
 	c1vc->verify_addr = (uint64_t) secure_rom_mem + SECURE_ROM_VERIFY_OFFSET;
 	c1vc->verify = c1vc_verify;
 
-	c1vc->cleanup = c1vc_cleanup;
-	c1vc->name = "c1vc";
-
 	prlog(PR_INFO, "STB: 'ibm,secureboot-v1' initialized\n");
 	return 0;
 }
@@ -299,6 +304,7 @@  int stb_final(void)
 	tpm_cleanup();
 	secure_mode = false;
 	trusted_mode = false;
+	cvc_free();
 	return (failed) ? STB_MEASURE_FAILED : 0;
 }