X-Git-Url: http://git.rot13.org/?p=osmocom-bb.git;a=blobdiff_plain;f=src%2Ftarget%2Ffirmware%2Fcomm%2Fmsgb.c;h=fbf874a2ca9b8f1eff74f4cd5e6e1b79c6132d96;hp=cf912ee130fcfcff59cd6a0d1205273c10bb5533;hb=fc16cbb578c7dcacf9d6dfc45625b4233570b659;hpb=6eba3fe6a5c9cf10f499897a46916402e203e062 diff --git a/src/target/firmware/comm/msgb.c b/src/target/firmware/comm/msgb.c index cf912ee..fbf874a 100644 --- a/src/target/firmware/comm/msgb.c +++ b/src/target/firmware/comm/msgb.c @@ -45,23 +45,24 @@ static struct supermsg msgs[MSGB_NUM]; void *_talloc_zero(void *ctx, unsigned int size, const char *name) { unsigned int i; + if (size > sizeof(struct msgb) + MSGB_DATA_SIZE) goto panic; - while (1) { - for (i = 0; i < ARRAY_SIZE(msgs); i++) { - if (!msgs[i].allocated) { - msgs[i].allocated = 1; - memset(&msgs[i].msg, 0, sizeof(&msgs[i].msg)); - memset(&msgs[i].buf, 0, sizeof(&msgs[i].buf)); - return &msgs[i].msg; - } + for (i = 0; i < ARRAY_SIZE(msgs); i++) { + if (!msgs[i].allocated) { + msgs[i].allocated = 1; + memset(&msgs[i].msg, 0, sizeof(&msgs[i].msg)); + memset(&msgs[i].buf, 0, sizeof(&msgs[i].buf)); + return &msgs[i].msg; } - cons_puts("unable to allocate msgb\n"); - delay_ms(50); } + panic: - return NULL; + cons_puts("unable to allocate msgb\n"); + while (1); + + return NULL; /* not reached */ } void talloc_free(void *msg) {