X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=common%2Fbloblist.c;h=99501951e0c068a57d3bfb8d988f96dbb85b1cc0;hb=04da42770b0cc3bea8841972bfc9568299ece826;hp=b4cf169b05a3d2ed9773df3dfb61818597ab861e;hpb=c06088b3601118485ae333efb27363383626858d;p=oweals%2Fu-boot.git diff --git a/common/bloblist.c b/common/bloblist.c index b4cf169b05..99501951e0 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -9,6 +9,7 @@ #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -58,11 +59,10 @@ static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp) struct bloblist_rec *rec; int new_alloced; - new_alloced = hdr->alloced + sizeof(*rec) + - ALIGN(size, BLOBLIST_ALIGN); + new_alloced = hdr->alloced + sizeof(*rec) + ALIGN(size, BLOBLIST_ALIGN); if (new_alloced >= hdr->size) { log(LOGC_BLOBLIST, LOGL_ERR, - "Failed to allocate %x bytes size=%x, need size>=%x\n", + "Failed to allocate %x bytes size=%x, need size=%x\n", size, hdr->size, new_alloced); return log_msg_ret("bloblist add", -ENOSPC); } @@ -73,6 +73,9 @@ static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp) rec->hdr_size = sizeof(*rec); rec->size = size; rec->spare = 0; + + /* Zero the record data */ + memset(rec + 1, '\0', rec->size); *recp = rec; return 0; @@ -84,8 +87,10 @@ static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size) rec = bloblist_findrec(tag); if (rec) { - if (size && size != rec->size) + if (size && size != rec->size) { + *recp = rec; return -ESPIPE; + } } else { int ret; @@ -144,6 +149,21 @@ void *bloblist_ensure(uint tag, int size) return (void *)rec + rec->hdr_size; } +int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp) +{ + struct bloblist_rec *rec; + int ret; + + ret = bloblist_ensurerec(tag, &rec, *sizep); + if (ret == -ESPIPE) + *sizep = rec->size; + else if (ret) + return ret; + *blobp = (void *)rec + rec->hdr_size; + + return 0; +} + static u32 bloblist_calc_chksum(struct bloblist_hdr *hdr) { struct bloblist_rec *rec;