diff options
author | Kevin Wolf <kwolf@redhat.com> | 2014-05-20 12:24:05 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-08-15 15:07:15 +0200 |
commit | 7d2a35cc921ea4832083a7e8598461868bb538ce (patch) | |
tree | 0aabab68f9ae59485bba04d9fe374ed0e603af1e /block.c | |
parent | 23d20b5b4fb7bde102e6779b7a13b88375e4db66 (diff) | |
download | qemu-7d2a35cc921ea4832083a7e8598461868bb538ce.zip |
block: Introduce qemu_try_blockalign()
This function returns NULL instead of aborting when an allocation fails.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -5258,6 +5258,19 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size) return qemu_memalign(bdrv_opt_mem_align(bs), size); } +void *qemu_try_blockalign(BlockDriverState *bs, size_t size) +{ + size_t align = bdrv_opt_mem_align(bs); + + /* Ensure that NULL is never returned on success */ + assert(align > 0); + if (size == 0) { + size = align; + } + + return qemu_try_memalign(align, size); +} + /* * Check if all memory in this vector is sector aligned. */ |