[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 08/10] qcow2-refcount: improve style of check_refcounts_l1()
From: |
Eric Blake |
Subject: |
Re: [PATCH 08/10] qcow2-refcount: improve style of check_refcounts_l1() |
Date: |
Tue, 4 May 2021 14:53:24 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 |
On 5/4/21 10:20 AM, Vladimir Sementsov-Ogievskiy wrote:
> - use g_autofree for l1_table
> - better name for size in bytes variable
> - reduce code blocks nesting
> - whitespaces, braces, newlines
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
> block/qcow2-refcount.c | 97 +++++++++++++++++++++---------------------
> 1 file changed, 49 insertions(+), 48 deletions(-)
>
> diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
> index 44fc0dd5dc..eb6de3dabd 100644
> --- a/block/qcow2-refcount.c
> +++ b/block/qcow2-refcount.c
> @@ -1864,71 +1864,72 @@ static int check_refcounts_l1(BlockDriverState *bs,
> int flags, BdrvCheckMode fix, bool active)
> {
> BDRVQcow2State *s = bs->opaque;
> - uint64_t *l1_table = NULL, l2_offset, l1_size2;
> + size_t l1_size_bytes = l1_size * L1E_SIZE;
> + g_autofree uint64_t *l1_table = g_try_malloc(l1_size_bytes);
Note that this now happens...
> + uint64_t l2_offset;
> int i, ret;
>
> - l1_size2 = l1_size * L1E_SIZE;
> + if (!l1_size) {
> + return 0;
...before you validate whether l1_size is non-zero, which can result in
g_try_malloc(0). Probably harmless, but it might be better if you declare
g_autofree uint64_t *l1_table = NULL;
and then initialize it via malloc only after the sanity check.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
- Re: [PATCH 03/10] qcow2: introduce qcow2_parse_compressed_l2_entry() helper, (continued)
- [PATCH 04/10] qcow2-refcount: introduce fix_l2_entry_by_zero(), Vladimir Sementsov-Ogievskiy, 2021/05/04
- [PATCH 05/10] qcow2-refcount: fix_l2_entry_by_zero(): also zero L2 entry bitmap, Vladimir Sementsov-Ogievskiy, 2021/05/04
- [PATCH 06/10] qcow2-refcount: check_refcounts_l2(): check l2_bitmap, Vladimir Sementsov-Ogievskiy, 2021/05/04
- [PATCH 07/10] qcow2-refcount: check_refcounts_l2(): check reserved bits, Vladimir Sementsov-Ogievskiy, 2021/05/04
- [PATCH 08/10] qcow2-refcount: improve style of check_refcounts_l1(), Vladimir Sementsov-Ogievskiy, 2021/05/04
- Re: [PATCH 08/10] qcow2-refcount: improve style of check_refcounts_l1(),
Eric Blake <=
- [PATCH 10/10] qcow2-refcount: check_refblocks(): add separate message for reserved, Vladimir Sementsov-Ogievskiy, 2021/05/04
- [PATCH 09/10] qcow2-refcount: check_refcounts_l1(): check reserved bits, Vladimir Sementsov-Ogievskiy, 2021/05/04
- [PATCH 02/10] qcow2: compressed read: simplify cluster descriptor passing, Vladimir Sementsov-Ogievskiy, 2021/05/04