From: Andrew Cooper Date: Thu, 15 Apr 2021 00:36:20 +0000 (+0100) Subject: gnttab: Fix scan-build core.CallAndMessage issues X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=dcd6c07b003c2f5500c8fef79a9405c185b53a87;p=xtf.git gnttab: Fix scan-build core.CallAndMessage issues scan-build complains: arch/x86/grant_table.c:41:17: warning: 1st function call argument is an uninitialized value [core.CallAndMessage] pte_from_gfn(gnttab_gfns[i], PF_SYM(AD, RW, P)), UVMF_INVLPG); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ because it can't observe that GNTTABOP_setup_table fills the variable on its success path. Initialising the array (which is currently one entry) isn't trivial because the array is variadic. Drop the nr_frames variable and use the sizeof() expression directly, to create compile-time constant size. A similar issue is reported against xsa-255, but this is trivial to resolve. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/grant_table.c b/arch/x86/grant_table.c index e8b4561..7b469a4 100644 --- a/arch/x86/grant_table.c +++ b/arch/x86/grant_table.c @@ -12,7 +12,7 @@ int arch_map_gnttab(void) { - unsigned int i, nr_frames = sizeof(gnttab_raw) / PAGE_SIZE; + unsigned int i; int rc = 0; /* Ensure gnttab_raw[] is a whole number of pages. */ @@ -20,7 +20,7 @@ int arch_map_gnttab(void) if ( IS_DEFINED(CONFIG_PV) ) { - unsigned long gnttab_gfns[nr_frames]; + unsigned long gnttab_gfns[sizeof(gnttab_raw) / PAGE_SIZE] = {}; struct gnttab_setup_table setup = { .dom = DOMID_SELF, .nr_frames = ARRAY_SIZE(gnttab_gfns), @@ -35,7 +35,7 @@ int arch_map_gnttab(void) return -EIO; } - for ( i = 0; !rc && i < nr_frames; ++i ) + for ( i = 0; !rc && i < ARRAY_SIZE(gnttab_gfns); ++i ) rc = hypercall_update_va_mapping( _u(&gnttab_raw[i * PAGE_SIZE]), pte_from_gfn(gnttab_gfns[i], PF_SYM(AD, RW, P)), UVMF_INVLPG); @@ -49,7 +49,8 @@ int arch_map_gnttab(void) .gfn = virt_to_gfn(gnttab_raw), }; - for ( i = 0; !rc && i < nr_frames; ++i, ++xatp.idx, ++xatp.gfn ) + for ( i = 0; !rc && i < (sizeof(gnttab_raw) / PAGE_SIZE); + ++i, ++xatp.idx, ++xatp.gfn ) rc = hypercall_memory_op(XENMEM_add_to_physmap, &xatp); } diff --git a/tests/xsa-255/main.c b/tests/xsa-255/main.c index f3db629..6fc382b 100644 --- a/tests/xsa-255/main.c +++ b/tests/xsa-255/main.c @@ -37,7 +37,7 @@ void test_main(void) return xtf_error("Error initialising grant table: %d\n", rc); /* Retrieve the status frames from Xen. */ - uint64_t status_frames[1]; + uint64_t status_frames[1] = {}; struct gnttab_get_status_frames gsf = { .dom = DOMID_SELF, .nr_frames = ARRAY_SIZE(status_frames),