Skip to content

Commit b40b830

Browse files
committed
[ot] hw/opentitan: replace assert() with g_assert()
Signed-off-by: Emmanuel Blot <[email protected]>
1 parent 60d0e9d commit b40b830

File tree

14 files changed

+78
-78
lines changed

14 files changed

+78
-78
lines changed

hw/opentitan/ot_aes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,8 @@ static void ot_aes_reset(DeviceState *dev)
12281228

12291229
timer_del(s->retard_timer);
12301230

1231-
assert(e->device);
1232-
assert(e->ep != UINT8_MAX);
1231+
g_assert(e->device);
1232+
g_assert(e->ep != UINT8_MAX);
12331233

12341234
s->prng = ot_prng_allocate();
12351235

hw/opentitan/ot_aon_timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ static void ot_aon_timer_reset(DeviceState *dev)
472472
{
473473
OtAonTimerState *s = OT_AON_TIMER(dev);
474474

475-
assert(s->pclk > 0);
475+
g_assert(s->pclk > 0);
476476

477477
timer_del(s->wkup_timer);
478478
timer_del(s->wdog_timer);

hw/opentitan/ot_clkmgr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static void ot_clkmgr_clock_hint(void *opaque, int irq, int level)
226226

227227
unsigned clock = (unsigned)irq;
228228

229-
assert(clock < OT_CLKMGR_HINT_COUNT);
229+
g_assert(clock < OT_CLKMGR_HINT_COUNT);
230230

231231
trace_ot_clkmgr_clock_hint(CLOCK_NAME(clock), clock, (bool)level);
232232

hw/opentitan/ot_csrng.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,17 @@ qemu_irq ot_csnrg_connect_hw_app(OtCSRNGState *s, unsigned app_id,
374374
qemu_irq req_sts, ot_csrng_genbit_filler_fn fn,
375375
void *opaque)
376376
{
377-
assert(app_id < OT_CSRNG_HW_APP_MAX);
378-
assert(req_sts);
379-
assert(fn);
377+
g_assert(app_id < OT_CSRNG_HW_APP_MAX);
378+
g_assert(req_sts);
379+
g_assert(fn);
380380

381381
OtCSRNGInstance *inst = &s->instances[app_id];
382382
/* if connection is invoked many times, there is no reason for changes */
383383
if (inst->hw.filler) {
384-
assert(inst->hw.filler == fn);
384+
g_assert(inst->hw.filler == fn);
385385
}
386386
if (inst->hw.req_sts) {
387-
assert(inst->hw.req_sts == req_sts);
387+
g_assert(inst->hw.req_sts == req_sts);
388388
}
389389
inst->hw.filler = fn;
390390
inst->hw.opaque = opaque;
@@ -399,15 +399,15 @@ qemu_irq ot_csnrg_connect_hw_app(OtCSRNGState *s, unsigned app_id,
399399
int ot_csrng_push_command(OtCSRNGState *s, unsigned app_id,
400400
const uint32_t *command)
401401
{
402-
assert(app_id < OT_CSRNG_HW_APP_MAX);
402+
g_assert(app_id < OT_CSRNG_HW_APP_MAX);
403403

404404
if (s->state == CSRNG_ERROR) {
405405
return -1;
406406
}
407407

408408
OtCSRNGInstance *inst = &s->instances[app_id];
409-
assert(inst->hw.filler);
410-
assert(inst->hw.req_sts);
409+
g_assert(inst->hw.filler);
410+
g_assert(inst->hw.req_sts);
411411

412412
ot_fifo32_reset(&inst->cmd_fifo);
413413
uint32_t acmd = FIELD_EX32(command[0], OT_CSNRG_CMD, ACMD);
@@ -553,7 +553,7 @@ static OtCSRNDCmdResult ot_csrng_drng_instanciate(
553553
int res;
554554
res = ecb_start(inst->parent->aes_cipher, key, (int)sizeof(key), 0,
555555
&drng->ecb);
556-
assert(res == CRYPT_OK);
556+
g_assert(res == CRYPT_OK);
557557

558558
memcpy(drng->key, key, OT_CSRNG_AES_KEY_SIZE);
559559
drng->instantiated = true;
@@ -602,7 +602,7 @@ static int ot_csrng_drng_update(OtCSRNGInstance *inst)
602602

603603
res = ecb_encrypt(drng->v_counter, ptmp, OT_CSRNG_AES_BLOCK_SIZE,
604604
&drng->ecb);
605-
assert(res == CRYPT_OK);
605+
g_assert(res == CRYPT_OK);
606606
ptmp += OT_CSRNG_AES_BLOCK_SIZE;
607607
}
608608

@@ -613,12 +613,12 @@ static int ot_csrng_drng_update(OtCSRNGInstance *inst)
613613
ot_csrng_drng_clear_material(inst);
614614

615615
res = ecb_done(&drng->ecb);
616-
assert(res == CRYPT_OK);
616+
g_assert(res == CRYPT_OK);
617617

618618
ptmp = (uint8_t *)tmp;
619619
res = ecb_start(inst->parent->aes_cipher, ptmp, (int)OT_CSRNG_AES_KEY_SIZE,
620620
0, &drng->ecb);
621-
assert(res == CRYPT_OK);
621+
g_assert(res == CRYPT_OK);
622622

623623
memcpy(drng->key, ptmp, OT_CSRNG_AES_KEY_SIZE);
624624
memcpy(drng->v_counter, &ptmp[OT_CSRNG_AES_KEY_SIZE],
@@ -636,7 +636,7 @@ static OtCSRNDCmdResult ot_csrng_drng_reseed(
636636
OtCSRNGInstance *inst, OtEntropySrcState *entropy_src, bool flag0)
637637
{
638638
OtCSRNGDrng *drng = &inst->drng;
639-
assert(drng->instantiated);
639+
g_assert(drng->instantiated);
640640

641641
if (!flag0) {
642642
if (!inst->parent->es_available) {
@@ -693,7 +693,7 @@ static void ot_csrng_drng_generate(OtCSRNGInstance *inst, uint32_t *out,
693693

694694
res = ecb_encrypt(drng->v_counter, (uint8_t *)out, OT_CSRNG_AES_BLOCK_SIZE,
695695
&drng->ecb);
696-
assert(res == CRYPT_OK);
696+
g_assert(res == CRYPT_OK);
697697

698698
xtrace_ot_csrng_show_buffer(ot_csrng_get_slot(inst), "out", out,
699699
OT_CSRNG_AES_BLOCK_SIZE);
@@ -713,7 +713,7 @@ static void ot_csrng_drng_generate(OtCSRNGInstance *inst, uint32_t *out,
713713
static unsigned ot_csrng_get_slot(OtCSRNGInstance *inst)
714714
{
715715
unsigned slot = (unsigned)(uintptr_t)(inst - &inst->parent->instances[0]);
716-
assert(slot <= SW_INSTANCE_ID);
716+
g_assert(slot <= SW_INSTANCE_ID);
717717
return slot;
718718
}
719719

@@ -1001,7 +1001,7 @@ ot_csrng_handle_instantiate(OtCSRNGState *s, unsigned slot)
10011001
const uint32_t *buffer =
10021002
ot_fifo32_peek_buf(&inst->cmd_fifo, ot_fifo32_num_used(&inst->cmd_fifo),
10031003
&num);
1004-
assert(num - 1u == clen);
1004+
g_assert(num - 1u == clen);
10051005
buffer += 1u;
10061006

10071007
if (clen) {
@@ -1055,7 +1055,7 @@ static int ot_csrng_handle_generate(OtCSRNGState *s, unsigned slot)
10551055
const uint32_t *buffer =
10561056
ot_fifo32_peek_buf(&inst->cmd_fifo,
10571057
ot_fifo32_num_used(&inst->cmd_fifo), &num);
1058-
assert(num - 1u == clen);
1058+
g_assert(num - 1u == clen);
10591059
buffer += 1u;
10601060
xtrace_ot_csrng_show_buffer(ot_csrng_get_slot(inst), "mat", buffer,
10611061
clen * sizeof(uint32_t));
@@ -1065,7 +1065,7 @@ static int ot_csrng_handle_generate(OtCSRNGState *s, unsigned slot)
10651065
trace_ot_csrng_generate(ot_csrng_get_slot(inst), packet_count);
10661066

10671067
OtCSRNGDrng *drng = &inst->drng;
1068-
assert(drng->instantiated);
1068+
g_assert(drng->instantiated);
10691069

10701070
if (ot_csrng_drng_remaining_count(inst)) {
10711071
xtrace_ot_csrng_info("remaining packets to generate",
@@ -1100,7 +1100,7 @@ static OtCSRNDCmdResult ot_csrng_handle_reseed(OtCSRNGState *s, unsigned slot)
11001100
const uint32_t *buffer =
11011101
ot_fifo32_peek_buf(&inst->cmd_fifo,
11021102
ot_fifo32_num_used(&inst->cmd_fifo), &num);
1103-
assert(num - 1u == clen);
1103+
g_assert(num - 1u == clen);
11041104
buffer += 1u;
11051105

11061106
xtrace_ot_csrng_show_buffer(ot_csrng_get_slot(inst), "mat", buffer,
@@ -1134,7 +1134,7 @@ static OtCSRNDCmdResult ot_csrng_handle_update(OtCSRNGState *s, unsigned slot)
11341134
const uint32_t *buffer =
11351135
ot_fifo32_peek_buf(&inst->cmd_fifo,
11361136
ot_fifo32_num_used(&inst->cmd_fifo), &num);
1137-
assert(num - 1u == clen);
1137+
g_assert(num - 1u == clen);
11381138
buffer += 1u;
11391139

11401140
xtrace_ot_csrng_show_buffer(ot_csrng_get_slot(inst), "mat", buffer,
@@ -1154,7 +1154,7 @@ static void ot_csrng_hwapp_ready_irq(void *opaque, int n, int level)
11541154
OtCSRNGState *s = opaque;
11551155

11561156
unsigned slot = (unsigned)n;
1157-
assert(slot < OT_CSRNG_HW_APP_MAX);
1157+
g_assert(slot < OT_CSRNG_HW_APP_MAX);
11581158
bool ready = (bool)level;
11591159

11601160
OtCSRNGInstance *inst = &s->instances[slot];
@@ -1267,7 +1267,7 @@ static int ot_csrng_handle_command(OtCSRNGState *s, unsigned slot)
12671267
case OT_CSRNG_CMD_RESEED:
12681268
break;
12691269
case OT_CSRNG_CMD_GENERATE:
1270-
assert(slot == SW_INSTANCE_ID || inst->hw.filler);
1270+
g_assert(slot == SW_INSTANCE_ID || inst->hw.filler);
12711271
break;
12721272
case OT_CSRNG_CMD_UPDATE:
12731273
case OT_CSRNG_CMD_UNINSTANTIATE:
@@ -1743,8 +1743,8 @@ static void ot_csrng_reset(DeviceState *dev)
17431743
{
17441744
OtCSRNGState *s = OT_CSRNG(dev);
17451745

1746-
assert(s->entropy_src);
1747-
assert(s->otp_ctrl);
1746+
g_assert(s->entropy_src);
1747+
g_assert(s->otp_ctrl);
17481748

17491749
timer_del(s->cmd_scheduler);
17501750

@@ -1764,7 +1764,7 @@ static void ot_csrng_reset(DeviceState *dev)
17641764

17651765
for (unsigned ix = 0; ix < OT_CSRNG_HW_APP_MAX + 1u; ix++) {
17661766
OtCSRNGInstance *inst = &s->instances[ix];
1767-
assert(inst->parent);
1767+
g_assert(inst->parent);
17681768
ot_fifo32_reset(&inst->cmd_fifo);
17691769
if (ix == SW_INSTANCE_ID) {
17701770
ot_fifo32_reset(&inst->sw.bits_fifo);

hw/opentitan/ot_edn.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@ static void ot_edn_csrng_ack_irq(void *opaque, int n, int level);
296296
void ot_edn_connect_endpoint(OtEDNState *s, unsigned ep_id,
297297
ot_edn_push_entropy_fn fn, void *opaque)
298298
{
299-
assert(ep_id < ENDPOINT_COUNT_MAX);
300-
assert(fn);
299+
g_assert(ep_id < ENDPOINT_COUNT_MAX);
300+
g_assert(fn);
301301

302302
OtEDNEndPoint *ep = &s->endpoints[ep_id];
303303
if (ep->fn) {
304-
assert(ep->fn == fn);
304+
g_assert(ep->fn == fn);
305305
} else {
306306
trace_ot_edn_connect_endpoint(s->rng.appid, ep_id);
307307
}
@@ -314,7 +314,7 @@ int ot_edn_request_entropy(OtEDNState *s, unsigned ep_id)
314314
{
315315
trace_ot_edn_request_entropy(s->rng.appid, ep_id);
316316

317-
assert(ep_id < ENDPOINT_COUNT_MAX);
317+
g_assert(ep_id < ENDPOINT_COUNT_MAX);
318318
OtEDNEndPoint *ep = &s->endpoints[ep_id];
319319
if (!ep->fn) {
320320
xtrace_ot_edn_error(s->rng.appid,
@@ -499,7 +499,7 @@ static int ot_edn_push_csrng_request(OtEDNState *s)
499499
req_sts = qdev_get_gpio_in_named(DEVICE(s), TYPE_OT_EDN "-req_sts", 0);
500500
c->genbits_ready = ot_csnrg_connect_hw_app(c->device, c->appid, req_sts,
501501
&ot_edn_fill_bits, s);
502-
assert(c->genbits_ready);
502+
g_assert(c->genbits_ready);
503503
}
504504
int res = ot_csrng_push_command(c->device, c->appid, c->buffer);
505505
if (res) {
@@ -577,7 +577,7 @@ static void ot_edn_try_auto_instantiate(OtEDNState *s)
577577

578578
uint32_t num = length;
579579
const uint32_t *cmd = ot_fifo32_pop_buf(&c->sw_cmd_fifo, num, &num);
580-
assert(num == length);
580+
g_assert(num == length);
581581
memcpy(c->buffer, cmd, length * sizeof(uint32_t));
582582

583583
if (ot_edn_push_csrng_request(s)) {
@@ -618,7 +618,7 @@ static void ot_edn_send_reseed_cmd(OtEDNState *s)
618618

619619
uint32_t num = length;
620620
const uint32_t *cmd = ot_fifo32_peek_buf(&c->cmd_reseed_fifo, num, &num);
621-
assert(num == length);
621+
g_assert(num == length);
622622
memcpy(c->buffer, cmd, length * sizeof(uint32_t));
623623

624624
if (ot_edn_push_csrng_request(s)) {
@@ -657,7 +657,7 @@ static void ot_edn_send_generate_cmd(OtEDNState *s)
657657

658658
uint32_t num = length;
659659
const uint32_t *cmd = ot_fifo32_peek_buf(&c->cmd_gen_fifo, num, &num);
660-
assert(num == length);
660+
g_assert(num == length);
661661
memcpy(c->buffer, cmd, length * sizeof(uint32_t));
662662
c->rem_packet_count = FIELD_EX32(c->buffer[0], OT_CSNRG_CMD, GLEN);
663663
xtrace_ot_edn_dinfo(c->appid, "Generate cmd w/ packets",
@@ -711,7 +711,7 @@ static void ot_edn_try_sw_request(OtEDNState *s)
711711
return;
712712
}
713713

714-
assert(s->state == EDN_SW_PORT_MODE);
714+
g_assert(s->state == EDN_SW_PORT_MODE);
715715

716716
uint32_t num = length;
717717
const uint32_t *cmd = ot_fifo32_peek_buf(&c->sw_cmd_fifo, num, &num);
@@ -744,7 +744,7 @@ static void ot_edn_handle_disable(OtEDNState *s)
744744
{
745745
OtEDNCSRNG *c = &s->rng;
746746

747-
assert(ot_edn_get_last_csrng_command(s) != OT_CSRNG_CMD_UNINSTANTIATE);
747+
g_assert(ot_edn_get_last_csrng_command(s) != OT_CSRNG_CMD_UNINSTANTIATE);
748748

749749
c->no_fips = false;
750750
c->rem_packet_count = 0;
@@ -1284,8 +1284,8 @@ static void ot_edn_reset(DeviceState *dev)
12841284
ot_fifo32_reset(&c->cmd_reseed_fifo);
12851285

12861286
/* check that properties have been initialized */
1287-
assert(c->device);
1288-
assert(c->appid < OT_CSRNG_HW_APP_MAX);
1287+
g_assert(c->device);
1288+
g_assert(c->appid < OT_CSRNG_HW_APP_MAX);
12891289
}
12901290

12911291
static void ot_edn_init(Object *obj)

hw/opentitan/ot_entropy_src.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ int ot_entropy_src_get_random(OtEntropySrcState *s, int genid,
523523
uint32_t *randu32 = (uint32_t *)random;
524524
size_t pos = 0;
525525
while (pos < ES_WORD_COUNT) {
526-
assert(!ot_fifo32_is_empty(&s->final_fifo));
526+
g_assert(!ot_fifo32_is_empty(&s->final_fifo));
527527
randu32[pos++] = ot_fifo32_pop(&s->final_fifo);
528528
}
529529

@@ -802,10 +802,10 @@ ot_entropy_src_push_entropy_to_conditioner(OtEntropySrcState *s, uint32_t word)
802802
if (s->cond_word == 0) {
803803
res = sha3_384_init(&s->sha3_state);
804804
ot_entropy_src_change_state(s, ENTROPY_SRC_SHA3_PREP);
805-
assert(res == CRYPT_OK);
805+
g_assert(res == CRYPT_OK);
806806
}
807807

808-
assert(!ot_fifo32_is_full(&s->precon_fifo));
808+
g_assert(!ot_fifo32_is_full(&s->precon_fifo));
809809

810810
ot_fifo32_push(&s->precon_fifo, word);
811811

@@ -818,11 +818,11 @@ ot_entropy_src_push_entropy_to_conditioner(OtEntropySrcState *s, uint32_t word)
818818
uint32_t size;
819819
const uint32_t *buf;
820820
buf = ot_fifo32_peek_buf(&s->precon_fifo, s->precon_fifo.num, &size);
821-
assert(size == s->precon_fifo.num);
821+
g_assert(size == s->precon_fifo.num);
822822
xtrace_ot_entropy_src_show_buffer("sha3 in", buf, size * sizeof(uint32_t));
823823
res = sha3_process(&s->sha3_state, (const uint8_t *)buf,
824824
size * sizeof(uint32_t));
825-
assert(res == CRYPT_OK);
825+
g_assert(res == CRYPT_OK);
826826
s->cond_word += size;
827827
ot_fifo32_reset(&s->precon_fifo);
828828

@@ -840,7 +840,7 @@ static void ot_entropy_src_perform_hash(OtEntropySrcState *s)
840840
uint32_t hash[OT_ENTROPY_SRC_WORD_COUNT];
841841
int res;
842842
res = sha3_done(&s->sha3_state, (uint8_t *)hash);
843-
assert(res == CRYPT_OK);
843+
g_assert(res == CRYPT_OK);
844844
s->cond_word = 0;
845845

846846
xtrace_ot_entropy_src_show_buffer("sha3 md", hash,
@@ -850,7 +850,7 @@ static void ot_entropy_src_perform_hash(OtEntropySrcState *s)
850850
ot_entropy_src_change_state(s, ENTROPY_SRC_SHA3_MSGDONE);
851851

852852
for (unsigned ix = 0; ix < OT_ENTROPY_SRC_WORD_COUNT; ix++) {
853-
assert(!ot_fifo32_is_full(&s->final_fifo));
853+
g_assert(!ot_fifo32_is_full(&s->final_fifo));
854854
ot_fifo32_push(&s->final_fifo, hash[ix]);
855855
}
856856
s->packet_count += 1u;
@@ -864,7 +864,7 @@ static void ot_entropy_src_perform_hash(OtEntropySrcState *s)
864864
static bool
865865
ot_entropy_src_push_bypass_entropy(OtEntropySrcState *s, uint32_t word)
866866
{
867-
assert(!ot_fifo32_is_full(&s->bypass_fifo));
867+
g_assert(!ot_fifo32_is_full(&s->bypass_fifo));
868868

869869
ot_fifo32_push(&s->bypass_fifo, word);
870870
if (!ot_fifo32_is_full(&s->bypass_fifo)) {
@@ -874,7 +874,7 @@ ot_entropy_src_push_bypass_entropy(OtEntropySrcState *s, uint32_t word)
874874

875875
/* bypass conditioner full/ready, empty it into the final FIFO */
876876
while (!ot_fifo32_is_empty(&s->bypass_fifo)) {
877-
assert(!ot_fifo32_is_full(&s->final_fifo));
877+
g_assert(!ot_fifo32_is_full(&s->final_fifo));
878878
ot_fifo32_push(&s->final_fifo, ot_fifo32_pop(&s->bypass_fifo));
879879
}
880880
s->packet_count += 1u;
@@ -1529,8 +1529,8 @@ static void ot_entropy_src_reset(DeviceState *dev)
15291529
{
15301530
OtEntropySrcState *s = OT_ENTROPY_SRC(dev);
15311531

1532-
assert(s->ast);
1533-
assert(s->otp_ctrl);
1532+
g_assert(s->ast);
1533+
g_assert(s->otp_ctrl);
15341534

15351535
timer_del(s->scheduler);
15361536

0 commit comments

Comments
 (0)