]> xenbits.xensource.com Git - people/aperard/xtf.git/commitdiff
gnttab: Fix scan-build core.CallAndMessage issues
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 15 Apr 2021 00:36:20 +0000 (01:36 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 16 Apr 2021 22:41:56 +0000 (23:41 +0100)
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 <andrew.cooper3@citrix.com>
arch/x86/grant_table.c
tests/xsa-255/main.c

index e8b4561830a67de42668b899eadd07c67a7e354e..7b469a4c3662503cc17b7d48c835bb2457f041ed 100644 (file)
@@ -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);
     }
 
index f3db629ed4bfa8ae6aba1f7ba3b17f1a3a0c763e..6fc382b28fb8c1d5ec2274ac25cc19990dfbbef7 100644 (file)
@@ -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),