>>> On 08.05.15 at 16:50, <andrew.coop...@citrix.com> wrote: > On 08/05/15 15:34, Roger Pau Monne wrote: >> + >> +void *vmalloc(unsigned long size) >> +{ >> + unsigned long *mfn; >> + unsigned long pages, i; >> + struct page_info *pg; >> + void *va = NULL; >> + >> + ASSERT(!in_irq()); >> + >> + if ( size == 0 ) >> + return ZERO_BLOCK_PTR; >> + >> + pages = DIV_ROUND_UP(size, PAGE_SIZE); >> + mfn = xzalloc_array(unsigned long, pages); > > This can avoid the zeroing if... > >> + if ( mfn == NULL ) >> + return NULL; >> + >> + for ( i = 0; i < pages; i++ ) >> + { >> + pg = alloc_domheap_pages(NULL, 1, 0); >> + if ( pg == NULL ) >> + goto error; >> + mfn[i] = page_to_mfn(pg); >> + } >> + >> + va = vmap(mfn, pages); >> + if ( va == NULL ) >> + goto error; >> + >> + xfree(mfn); >> + return va; >> + >> + error: >> + vunmap(va); >> + for ( i = 0; i < pages; i++ ) >> + if ( mfn[i] != 0 ) >> + free_domheap_pages(mfn_to_page(mfn[i]), 1); > > this loop turns into > > while ( i ) > free_domheap_pages(mfn_to_page(mfn[--i], 1);
or (preferably imo) while ( i-- ) free_domheap_pages(mfn_to_page(mfn[i], 1); Jan _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel