memory: Move FlatView allocation to a helper
This moves a FlatView allocation and initialization to a helper. While we are nere, replace g_new with g_new0 to not to bother if we add new fields in the future. This should cause no behavioural change. Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Message-Id: <20170921085110.25598-4-aik@ozlabs.ru> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
		
							parent
							
								
									9a62e24f45
								
							
						
					
					
						commit
						cc94cd6d36
					
				
							
								
								
									
										16
									
								
								memory.c
								
								
								
								
							
							
						
						
									
										16
									
								
								memory.c
								
								
								
								
							| 
						 | 
				
			
			@ -258,12 +258,14 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b)
 | 
			
		|||
        && a->readonly == b->readonly;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void flatview_init(FlatView *view)
 | 
			
		||||
static FlatView *flatview_new(void)
 | 
			
		||||
{
 | 
			
		||||
    FlatView *view;
 | 
			
		||||
 | 
			
		||||
    view = g_new0(FlatView, 1);
 | 
			
		||||
    view->ref = 1;
 | 
			
		||||
    view->ranges = NULL;
 | 
			
		||||
    view->nr = 0;
 | 
			
		||||
    view->nr_allocated = 0;
 | 
			
		||||
 | 
			
		||||
    return view;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Insert a range into a given position.  Caller is responsible for maintaining
 | 
			
		||||
| 
						 | 
				
			
			@ -707,8 +709,7 @@ static FlatView *generate_memory_topology(MemoryRegion *mr)
 | 
			
		|||
{
 | 
			
		||||
    FlatView *view;
 | 
			
		||||
 | 
			
		||||
    view = g_new(FlatView, 1);
 | 
			
		||||
    flatview_init(view);
 | 
			
		||||
    view = flatview_new();
 | 
			
		||||
 | 
			
		||||
    if (mr) {
 | 
			
		||||
        render_memory_region(view, mr, int128_zero(),
 | 
			
		||||
| 
						 | 
				
			
			@ -2629,8 +2630,7 @@ void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
 | 
			
		|||
    as->ref_count = 1;
 | 
			
		||||
    as->root = root;
 | 
			
		||||
    as->malloced = false;
 | 
			
		||||
    as->current_map = g_new(FlatView, 1);
 | 
			
		||||
    flatview_init(as->current_map);
 | 
			
		||||
    as->current_map = flatview_new();
 | 
			
		||||
    as->ioeventfd_nb = 0;
 | 
			
		||||
    as->ioeventfds = NULL;
 | 
			
		||||
    QTAILQ_INIT(&as->listeners);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue