migration: Use g_autofree to simplify ram_dirty_bitmap_reload()
PATCH 1/1 migration: Use g_autofree to simplify ram_dirty_bitmap_reload()
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
---
Based-on: <ZR7e3cmxCH9LAdnS@x1n>
--- migration/ram.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
migration/ram.c +6 -9
@@ -4164,11 +4164,11 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp) {/* from_dst_file is always valid because we're within rp_thread */ QEMUFile *file = s->rp_state.from_dst_file; -unsigned long *le_bitmap, nbits = block->used_length >>TARGET_PAGE_BITS ; +unsigned long *le_bitmap =NULL ; +unsigned long nbits = block->used_length >>TARGET_PAGE_BITS ;uint64_t local_size =DIV_ROUND_UP (nbits,8 );uint64_t size, end_mark;RAMState *rs = ram_state; -bool result = false;trace_ram_dirty_bitmap_reload_begin (block->idstr);
@@ -4193,7 +4193,7 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)if (size != local_size) {error_setg (errp,"ramblock '%s' bitmap size mismatch (0x%" PRIx64" != 0x%" PRIx64")" , block->idstr, size, local_size); - goto out; +return false; } size =qemu_get_buffer (file, (uint8_t *)le_bitmap, local_size);
@@ -4203,13 +4203,13 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)error_setg (errp,"read bitmap failed for ramblock '%s': " "(size 0x%" PRIx64", got: 0x%" PRIx64")" , block->idstr, local_size, size); - goto out; +return false; }if (end_mark !=RAMBLOCK_RECV_BITMAP_ENDING ) {error_setg (errp,"ramblock '%s' end mark incorrect: 0x%" PRIx64, block->idstr, end_mark); - goto out; +return false; }/*
@@ -4241,10 +4241,7 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)*/ migration_rp_kick (s); - result = true; -out: -g_free (le_bitmap); -return result; +return true; }static int ram_resume_prepare (MigrationState *s,void *opaque)
Signature · 1 line
2.41.0
Quoted 12 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Based-on: <ZR7e3cmxCH9LAdnS@x1n>--- migration/ram.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)migration/ram.c +0
-0
migration/ram.c bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp) · line 4167
Quoted 5 lines
migration/ram.c +1
-1@@ -4164,11 +4164,11 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp) {/* from_dst_file is always valid because we're within rp_thread */ QEMUFile *file = s->rp_state.from_dst_file; -unsigned long *le_bitmap, nbits = block->used_length >>TARGET_PAGE_BITS ; +unsigned long *le_bitmap =NULL ;
Aren't you missing the actual g_autofree here?
Quoted 45 lines
migration/ram.c +5
-8+unsigned long nbits = block->used_length >>TARGET_PAGE_BITS ;uint64_t local_size =DIV_ROUND_UP (nbits,8 );uint64_t size, end_mark;RAMState *rs = ram_state; -bool result = false;trace_ram_dirty_bitmap_reload_begin (block->idstr);@@ -4193,7 +4193,7 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)if (size != local_size) {error_setg (errp,"ramblock '%s' bitmap size mismatch (0x%" PRIx64" != 0x%" PRIx64")" , block->idstr, size, local_size); - goto out; +return false; } size =qemu_get_buffer (file, (uint8_t *)le_bitmap, local_size);@@ -4203,13 +4203,13 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)error_setg (errp,"read bitmap failed for ramblock '%s': " "(size 0x%" PRIx64", got: 0x%" PRIx64")" , block->idstr, local_size, size); - goto out; +return false; }if (end_mark !=RAMBLOCK_RECV_BITMAP_ENDING ) {error_setg (errp,"ramblock '%s' end mark incorrect: 0x%" PRIx64, block->idstr, end_mark); - goto out; +return false; }/* @@ -4241,10 +4241,7 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp)*/ migration_rp_kick (s); - result = true; -out: -g_free (le_bitmap); -return result; +return true; }static int ram_resume_prepare (MigrationState *s,void *opaque)
Quoted 9 lines · Fabiano Rosas
Quoted 7 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Based-on: <ZR7e3cmxCH9LAdnS@x1n>--- migration/ram.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
Quoted 12 lines
migration/ram.c bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp) · line 4167
Quoted 10 lines
migration/ram.c +1
-1@@ -4164,11 +4164,11 @@ bool ram_dirty_bitmap_reload(MigrationState *s, RAMBlock *block, Error **errp) {/* from_dst_file is always valid because we're within rp_thread */ QEMUFile *file = s->rp_state.from_dst_file; -unsigned long *le_bitmap, nbits = block->used_length >>TARGET_PAGE_BITS ; +unsigned long *le_bitmap =NULL ;Aren't you missing the actual
g_autofreehere?
Argh 🤦🏻 sorry...