From: Andrew Cooper Date: Mon, 6 Jan 2020 13:26:28 +0000 (+0000) Subject: Coverity: Improve model for {,un}map_domain_page() X-Git-Tag: archive/raspbian/4.14.0+80-gd101b417b7-1+rpi1^2~63^2~940 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=18dca1410d4120cb276028e400efa045c5c8a972;p=xen.git Coverity: Improve model for {,un}map_domain_page() The first attempt resulted in several "Free of address-of expression (BAD_FREE)" issues, because of code which relies on the fact that any pointer in the same page is ok to pass to unmap_domain_page() Model this property to remove the issues. Coverity IDs: 1135356 113536{0,1} 1401300 141809{0,1} 1438864 Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- diff --git a/misc/coverity/model.c b/misc/coverity/model.c index bd62566a0d..1ec3fe8673 100644 --- a/misc/coverity/model.c +++ b/misc/coverity/model.c @@ -82,21 +82,31 @@ void xfree(void *va) * allocation of exactly 1 page. * * map_domain_page() never fails. (It will BUG() before returning NULL) - * - * TODO: work out how to correctly model the behaviour that this function will - * only ever return page aligned pointers. */ void *map_domain_page(unsigned long mfn) { - return __coverity_alloc__(PAGE_SIZE); + unsigned long ptr = (unsigned long)__coverity_alloc__(PAGE_SIZE); + + /* + * Expressing the alignment of the memory allocation isn't possible. As a + * substitute, tell Coverity to ignore any path where ptr isn't page + * aligned. + */ + if ( ptr & ~PAGE_MASK ) + __coverity_panic__(); + + return (void *)ptr; } /* - * unmap_domain_page() will unmap a page. Model it as a free(). + * unmap_domain_page() will unmap a page. Model it as a free(). Any *va + * within the page is valid to pass. */ void unmap_domain_page(const void *va) { - __coverity_free__(va); + unsigned long ptr = (unsigned long)va & PAGE_MASK; + + __coverity_free__((void *)ptr); } /*