Skip to content

Commit 59b958b

Browse files
committed
Remove all traces of WOLFHSM_CFG_FLASH_RAMSIM_MALLOC. Move arg checks to top of function.
1 parent 6420f3b commit 59b958b

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

src/wh_flash_ramsim.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
#include <stdint.h>
2828
#include <stddef.h> /* For NULL */
2929

30-
#if defined(WOLFHSM_CFG_FLASH_RAMSIM_MALLOC)
31-
#include <stdlib.h> /* For malloc/free */
32-
#endif
33-
3430
#include <string.h>
3531
#include <stdbool.h>
3632

@@ -63,21 +59,19 @@ int whFlashRamsim_Init(void* context, const void* config)
6359
const whFlashRamsimCfg* cfg = (const whFlashRamsimCfg*)config;
6460

6561
if (ctx == NULL || cfg == NULL || (cfg->sectorSize == 0) ||
66-
(cfg->pageSize == 0) || (cfg->sectorSize % cfg->pageSize != 0)) {
62+
(cfg->pageSize == 0) || (cfg->sectorSize % cfg->pageSize != 0) ||
63+
cfg->memory == NULL || cfg->size == 0) {
6764
return WH_ERROR_BADARGS;
6865
}
6966

67+
memset(ctx, 0, sizeof(*ctx);
7068
ctx->size = cfg->size;
7169
ctx->sectorSize = cfg->sectorSize;
7270
ctx->pageSize = cfg->pageSize;
7371
ctx->memory = cfg->memory;
7472
ctx->erasedByte = cfg->erasedByte;
7573
ctx->writeLocked = 0;
7674

77-
if (!ctx->memory) {
78-
return WH_ERROR_BADARGS;
79-
}
80-
8175
/* Initialize memory based on initData or simulate starting from erased flash */
8276
if (cfg->initData != NULL) {
8377
memcpy(ctx->memory, cfg->initData, ctx->size);
@@ -96,13 +90,6 @@ int whFlashRamsim_Cleanup(void* context)
9690
return WH_ERROR_BADARGS;
9791
}
9892

99-
#if defined(WOLFHSM_CFG_FLASH_RAMSIM_MALLOC)
100-
if (ctx->memory != NULL) {
101-
free(ctx->memory);
102-
ctx->memory = NULL;
103-
}
104-
#endif
105-
10693
return WH_ERROR_OK;
10794
}
10895

0 commit comments

Comments
 (0)