diff --git a/drivers/mxc/vpu_windsor/vpu_encoder_b0.c b/drivers/mxc/vpu_windsor/vpu_encoder_b0.c
index 8a58ae7418036addd00b96a1bc411d103bd36d36..ff4a8a2b980abe16e386e38d10679ebe56996446 100644
--- a/drivers/mxc/vpu_windsor/vpu_encoder_b0.c
+++ b/drivers/mxc/vpu_windsor/vpu_encoder_b0.c
@@ -3382,12 +3382,18 @@ static int set_vpu_fw_addr(struct vpu_dev *dev, struct core_device *core_dev)
 	return 0;
 }
 
+static void cleanup_firmware_memory(struct core_device *core_dev)
+{
+	memset_io(core_dev->m0_p_fw_space_vir, 0, core_dev->fw_buf_size);
+}
+
 static int vpu_firmware_download(struct vpu_dev *This, u_int32 core_id)
 {
 	const struct firmware *m0_pfw = NULL;
 	const u8 *image;
 	unsigned int FW_Size = 0;
 	int ret = 0;
+	struct core_device *core_dev = &This->core_dev[core_id];
 	char *p = This->core_dev[core_id].m0_p_fw_space_vir;
 
 	vpu_log_func();
@@ -3406,7 +3412,8 @@ static int vpu_firmware_download(struct vpu_dev *This, u_int32 core_id)
 	FW_Size = min_t(u32, m0_pfw->size, This->core_dev[core_id].fw_buf_size);
 	This->core_dev[core_id].fw_actual_size = FW_Size;
 
-	memcpy(This->core_dev[core_id].m0_p_fw_space_vir, image, FW_Size);
+	cleanup_firmware_memory(core_dev);
+	memcpy(core_dev->m0_p_fw_space_vir, image, FW_Size);
 	p[16] = This->plat_type;
 	p[17] = core_id + 1;
 	p[18] = 1;
@@ -5235,7 +5242,7 @@ static int init_vpu_core_dev(struct core_device *core_dev)
 	if (!core_dev->m0_p_fw_space_vir)
 		vpu_err("failed to remap space for M0 firmware\n");
 
-	memset_io(core_dev->m0_p_fw_space_vir, 0, core_dev->fw_buf_size);
+	cleanup_firmware_memory(core_dev);
 
 	core_dev->m0_rpc_virt =
 		ioremap_wc(core_dev->m0_rpc_phy,