summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2019-04-10 17:11:59 +0800
committerchrome-bot <chrome-bot@chromium.org>2019-04-17 21:32:26 -0700
commit144d06f8e74d8c4aa25d24a8e483db3e841e9e7d (patch)
tree71dff1821aed923e96a72de5ff7df6cb272e1d73
parentdccea9ae88059c8cb7dff76d2682835184fc8338 (diff)
downloadvboot-144d06f8e74d8c4aa25d24a8e483db3e841e9e7d.tar.gz
vboot: remove workbuf alloc and free code
Workbuf should be allocated and free'd by vboot caller. BUG=b:124141368, chromium:951692 TEST=make clean && make runtests CQ-DEPEND=CL:1563872 BRANCH=none Change-Id: Ibaa70f62c660d46cc083a5e55a73b961eb813649 Signed-off-by: Joel Kitching <kitching@google.com> Reviewed-on: https://chromium-review.googlesource.com/1560716 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Joel Kitching <kitching@chromium.org> Reviewed-by: Joel Kitching <kitching@chromium.org>
-rw-r--r--firmware/lib/vboot_api_kernel.c41
-rw-r--r--tests/vboot_api_kernel4_tests.c7
-rw-r--r--tests/vboot_api_kernel5_tests.c7
3 files changed, 16 insertions, 39 deletions
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index c08ca131..11a16595 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -26,7 +26,6 @@
/* Global variables */
static struct RollbackSpaceFwmp fwmp;
static LoadKernelParams lkp;
-static uint8_t *unaligned_workbuf;
#ifdef CHROMEOS_ENVIRONMENT
/* Global variable accessors for unit tests */
@@ -224,6 +223,12 @@ static VbError_t vb2_kernel_setup(struct vb2_context *ctx,
VbCommonParams *cparams,
VbSelectAndLoadKernelParams *kparams)
{
+ if (VB2_SUCCESS != vb2_init_context(ctx)) {
+ VB2_DEBUG("Can't init vb2_context\n");
+ VbSetRecoveryRequest(ctx, VB2_RECOVERY_RW_SHARED_DATA);
+ return VBERROR_INIT_SHARED_DATA;
+ }
+
VbSharedDataHeader *shared =
(VbSharedDataHeader *)cparams->shared_data_blob;
@@ -255,31 +260,6 @@ static VbError_t vb2_kernel_setup(struct vb2_context *ctx,
VbExNvStorageRead(ctx->nvdata);
vb2_nv_init(ctx);
- ctx->workbuf_size = VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE +
- VB2_WORKBUF_ALIGN;
-
- unaligned_workbuf = ctx->workbuf = malloc(ctx->workbuf_size);
- if (!unaligned_workbuf) {
- VB2_DEBUG("Can't allocate work buffer\n");
- VbSetRecoveryRequest(ctx, VB2_RECOVERY_RW_SHARED_DATA);
- return VBERROR_INIT_SHARED_DATA;
- }
-
- if (VB2_SUCCESS != vb2_align(&ctx->workbuf, &ctx->workbuf_size,
- VB2_WORKBUF_ALIGN,
- VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE)) {
- VB2_DEBUG("Can't align work buffer\n");
- VbSetRecoveryRequest(ctx, VB2_RECOVERY_RW_SHARED_DATA);
- return VBERROR_INIT_SHARED_DATA;
- }
-
- if (VB2_SUCCESS != vb2_init_context(ctx)) {
- VB2_DEBUG("Can't init vb2_context\n");
- free(unaligned_workbuf);
- VbSetRecoveryRequest(ctx, VB2_RECOVERY_RW_SHARED_DATA);
- return VBERROR_INIT_SHARED_DATA;
- }
-
struct vb2_shared_data *sd = vb2_get_sd(ctx);
sd->recovery_reason = shared->recovery_reason;
@@ -381,15 +361,6 @@ static void vb2_kernel_cleanup(struct vb2_context *ctx, VbCommonParams *cparams)
VbSharedDataHeader *shared =
(VbSharedDataHeader *)cparams->shared_data_blob;
- /*
- * Clean up vboot context.
- *
- * TODO: This should propagate up to higher levels
- */
-
- /* Free buffers */
- free(unaligned_workbuf);
-
vb2_nv_commit(ctx);
/* Stop timer */
diff --git a/tests/vboot_api_kernel4_tests.c b/tests/vboot_api_kernel4_tests.c
index ab9d557f..cb2179d5 100644
--- a/tests/vboot_api_kernel4_tests.c
+++ b/tests/vboot_api_kernel4_tests.c
@@ -25,6 +25,7 @@
#include "vboot_struct.h"
/* Mock data */
+static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
static struct vb2_context ctx;
static struct vb2_context ctx_nvram_backend;
static VbCommonParams cparams;
@@ -59,9 +60,11 @@ static void ResetMocks(void)
gbb.minor_version = GBB_MINOR_VER;
gbb.flags = 0;
- /* ctx.workbuf will be allocated and initialized by
- * VbSelectAndLoadKernel. */
+ /* ctx.workbuf will be initialized by VbSelectAndLoadKernel. */
memset(&ctx, 0, sizeof(ctx));
+ ctx.workbuf = workbuf;
+ ctx.workbuf_size = sizeof(workbuf);
+ vb2_init_context(&ctx);
/*
* ctx_nvram_backend is only used as an NVRAM backend (see
diff --git a/tests/vboot_api_kernel5_tests.c b/tests/vboot_api_kernel5_tests.c
index 65899aec..8d3281be 100644
--- a/tests/vboot_api_kernel5_tests.c
+++ b/tests/vboot_api_kernel5_tests.c
@@ -27,6 +27,7 @@
#include "vboot_struct.h"
/* Mock data */
+static uint8_t workbuf[VB2_KERNEL_WORKBUF_RECOMMENDED_SIZE];
static struct vb2_context ctx;
static struct vb2_context ctx_nvram_backend;
static VbCommonParams cparams;
@@ -67,9 +68,11 @@ static void ResetMocks(void)
gbb->rootkey_offset = sizeof(*gbb);
gbb->rootkey_size = sizeof(VbPublicKey);
- /* ctx.workbuf will be allocated and initialized by
- * VbVerifyMemoryBootImage. */
+ /* ctx.workbuf will be initialized by VbVerifyMemoryBootImage. */
memset(&ctx, 0, sizeof(ctx));
+ ctx.workbuf = workbuf;
+ ctx.workbuf_size = sizeof(workbuf);
+ vb2_init_context(&ctx);
/*
* ctx_nvram_backend is only used as an NVRAM backend (see