Skip to content

Commit 60c37e1

Browse files
authored
dmi_scan() allocate bytes depending on abits value (#307)
* dmi_scan() allocate bytes depending on abits value Fixes #303. Change-Id: Iac45959cf342180c60cd0b5462f864ad81beddd2 * Incorporate review feedback. Change-Id: I1cc7d20fed6f2d891bec0e858fca53ece450720c
1 parent b986d29 commit 60c37e1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/target/riscv/riscv-013.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,18 @@ static dmi_status_t dmi_scan(struct target *target, uint32_t *address_in,
458458
bool exec)
459459
{
460460
riscv013_info_t *info = get_info(target);
461-
uint8_t in[8] = {0};
462-
uint8_t out[8];
461+
unsigned num_bits = info->abits + DTM_DMI_OP_LENGTH + DTM_DMI_DATA_LENGTH;
462+
size_t num_bytes = (num_bits + 7) / 8;
463+
uint8_t in[num_bytes];
464+
uint8_t out[num_bytes];
463465
struct scan_field field = {
464-
.num_bits = info->abits + DTM_DMI_OP_LENGTH + DTM_DMI_DATA_LENGTH,
466+
.num_bits = num_bits,
465467
.out_value = out,
466468
.in_value = in
467469
};
468470

471+
memset(in, 0, num_bytes);
472+
469473
assert(info->abits != 0);
470474

471475
buf_set_u32(out, DTM_DMI_OP_OFFSET, DTM_DMI_OP_LENGTH, op);

0 commit comments

Comments
 (0)