@@ -92,7 +92,6 @@ int fwu_get_active_index(u32 *active_idx)
int fwu_update_active_index(u32 active_idx)
{
int ret;
- void *buf;
struct fwu_mdata *mdata = NULL;
if (active_idx > CONFIG_FWU_NUM_BANKS) {
@@ -113,14 +112,6 @@ int fwu_update_active_index(u32 active_idx)
mdata->previous_active_index = mdata->active_index;
mdata->active_index = active_idx;
- /*
- * Calculate the crc32 for the updated FWU metadata
- * and put the updated value in the FWU metadata crc32
- * field
- */
- buf = &mdata->version;
- mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32));
-
/*
* Now write this updated FWU metadata to both the
* FWU metadata partitions
@@ -205,7 +196,6 @@ int fwu_mdata_check(void)
int fwu_revert_boot_index(void)
{
int ret;
- void *buf;
u32 cur_active_index;
struct fwu_mdata *mdata = NULL;
@@ -223,14 +213,6 @@ int fwu_revert_boot_index(void)
mdata->active_index = mdata->previous_active_index;
mdata->previous_active_index = cur_active_index;
- /*
- * Calculate the crc32 for the updated FWU metadata
- * and put the updated value in the FWU metadata crc32
- * field
- */
- buf = &mdata->version;
- mdata->crc32 = crc32(0, buf, sizeof(*mdata) - sizeof(u32));
-
/*
* Now write this updated FWU metadata to both the
* FWU metadata partitions
@@ -161,6 +161,14 @@ static int fwu_gpt_update_mdata(struct fwu_mdata *mdata)
return -ENODEV;
}
+ /*
+ * Calculate the crc32 for the updated FWU metadata
+ * and put the updated value in the FWU metadata crc32
+ * field
+ */
+ mdata->crc32 = crc32(0, (void *)&mdata->version,
+ sizeof(*mdata) - sizeof(u32));
+
/* First write the primary partition*/
ret = gpt_write_mdata_partition(desc, mdata, primary_mpart);
if (ret < 0) {
@@ -457,7 +465,6 @@ int fwu_gpt_get_mdata(struct fwu_mdata **mdata)
static int fwu_gpt_set_clear_image_accept(efi_guid_t *img_type_id,
u32 bank, u8 action)
{
- void *buf;
int ret, i;
u32 nimages;
struct fwu_mdata *mdata = NULL;
@@ -480,10 +487,6 @@ static int fwu_gpt_set_clear_image_accept(efi_guid_t *img_type_id,
else
img_bank_info->accepted = 0;
- buf = &mdata->version;
- mdata->crc32 = crc32(0, buf, sizeof(*mdata) -
- sizeof(u32));
-
ret = fwu_gpt_update_mdata(mdata);
goto out;
}
To avoid calculating crc32 in several places, do it in gpt_update_mdata(). This also ensures the mdata crc32 is always sane. Signed-off-by: Masami Hiramatsu <masami.hiramatsu@linaro.org> --- lib/fwu_updates/fwu_mdata.c | 18 ------------------ lib/fwu_updates/fwu_mdata_gpt_blk.c | 13 ++++++++----- 2 files changed, 8 insertions(+), 23 deletions(-)