mirror of https://github.com/xemu-project/xemu.git
hv-balloon: avoid alloca() usage
alloca() is frowned upon, replace it with g_malloc0() + g_autofree. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: David Hildenbrand <david@redhat.com> Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
This commit is contained in:
parent
8f6330a807
commit
1d3b82eabb
|
@ -366,7 +366,7 @@ static void hv_balloon_unballoon_posting(HvBalloon *balloon, StateDesc *stdesc)
|
||||||
PageRangeTree dtree;
|
PageRangeTree dtree;
|
||||||
uint64_t *dctr;
|
uint64_t *dctr;
|
||||||
bool our_range;
|
bool our_range;
|
||||||
struct dm_unballoon_request *ur;
|
g_autofree struct dm_unballoon_request *ur = NULL;
|
||||||
size_t ur_size = sizeof(*ur) + sizeof(ur->range_array[0]);
|
size_t ur_size = sizeof(*ur) + sizeof(ur->range_array[0]);
|
||||||
PageRange range;
|
PageRange range;
|
||||||
bool bret;
|
bool bret;
|
||||||
|
@ -388,8 +388,7 @@ static void hv_balloon_unballoon_posting(HvBalloon *balloon, StateDesc *stdesc)
|
||||||
assert(dtree.t);
|
assert(dtree.t);
|
||||||
assert(dctr);
|
assert(dctr);
|
||||||
|
|
||||||
ur = alloca(ur_size);
|
ur = g_malloc0(ur_size);
|
||||||
memset(ur, 0, ur_size);
|
|
||||||
ur->hdr.type = DM_UNBALLOON_REQUEST;
|
ur->hdr.type = DM_UNBALLOON_REQUEST;
|
||||||
ur->hdr.size = ur_size;
|
ur->hdr.size = ur_size;
|
||||||
ur->hdr.trans_id = balloon->trans_id;
|
ur->hdr.trans_id = balloon->trans_id;
|
||||||
|
@ -531,7 +530,7 @@ static void hv_balloon_hot_add_posting(HvBalloon *balloon, StateDesc *stdesc)
|
||||||
PageRange *hot_add_range = &balloon->hot_add_range;
|
PageRange *hot_add_range = &balloon->hot_add_range;
|
||||||
uint64_t *current_count = &balloon->ha_current_count;
|
uint64_t *current_count = &balloon->ha_current_count;
|
||||||
VMBusChannel *chan = hv_balloon_get_channel(balloon);
|
VMBusChannel *chan = hv_balloon_get_channel(balloon);
|
||||||
struct dm_hot_add *ha;
|
g_autofree struct dm_hot_add *ha = NULL;
|
||||||
size_t ha_size = sizeof(*ha) + sizeof(ha->range);
|
size_t ha_size = sizeof(*ha) + sizeof(ha->range);
|
||||||
union dm_mem_page_range *ha_region;
|
union dm_mem_page_range *ha_region;
|
||||||
uint64_t align, chunk_max_size;
|
uint64_t align, chunk_max_size;
|
||||||
|
@ -560,9 +559,8 @@ static void hv_balloon_hot_add_posting(HvBalloon *balloon, StateDesc *stdesc)
|
||||||
*/
|
*/
|
||||||
*current_count = MIN(hot_add_range->count, chunk_max_size);
|
*current_count = MIN(hot_add_range->count, chunk_max_size);
|
||||||
|
|
||||||
ha = alloca(ha_size);
|
ha = g_malloc0(ha_size);
|
||||||
ha_region = &(&ha->range)[1];
|
ha_region = &(&ha->range)[1];
|
||||||
memset(ha, 0, ha_size);
|
|
||||||
ha->hdr.type = DM_MEM_HOT_ADD_REQUEST;
|
ha->hdr.type = DM_MEM_HOT_ADD_REQUEST;
|
||||||
ha->hdr.size = ha_size;
|
ha->hdr.size = ha_size;
|
||||||
ha->hdr.trans_id = balloon->trans_id;
|
ha->hdr.trans_id = balloon->trans_id;
|
||||||
|
|
Loading…
Reference in New Issue