Skip to content

Commit cb0f475

Browse files
00xcavpatel
authored andcommitted
lib: sbi: fwft: fix incorrect size passed to sbi_zalloc()
The fwt_hart_state struct inciludes a flexible array member, so its allocation size will be that of the struct itself, plus that of each of the members in the array. When calculating this size, instead of taking the size of the struct, the size of a pointer to it was taken, which is incorrect. Luckily, this happenned to not produce memory corruption because the size of the non-flexible members of the struct is the same as the size of a pointer. Signed-off-by: Carlos López <[email protected]> Reviewed-by: Anup Patel <[email protected]>
1 parent baf6a75 commit cb0f475

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/sbi/sbi_fwft.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ int sbi_fwft_init(struct sbi_scratch *scratch, bool cold_boot)
251251

252252
fhs = fwft_get_hart_state_ptr(scratch);
253253
if (!fhs) {
254-
fhs = sbi_zalloc(sizeof(fhs) + array_size(features) * sizeof(struct fwft_config));
254+
fhs = sbi_zalloc(sizeof(*fhs) + array_size(features) * sizeof(struct fwft_config));
255255
if (!fhs)
256256
return SBI_ENOMEM;
257257

0 commit comments

Comments
 (0)