Skip to contentSkip to conversation

x86/mm: Fix possible increment of uninitialised variable

PATCH In review Andrew Cooper 3 participants 3 messages Sep 9, 2013 – Sep 10, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm: Fix possible increment of uninitialised variable

Discovered by Coverity, CID 1056101

When taking the continue branch on the first iteration of the loop, gfn would indeed be uninitialised when incremented. However, as gfn is unconditionally constructed from i{1..4} before use in the loop body, having it incremented in the loop header is useless.

Therefore, simply remove it.

CC Keir Fraser <[email protected]>
CC Jan Beulich <[email protected]>
CC Tim Deegan <[email protected]>

---

I have compile tested this but not functionally tested it. It is fairly obvious from the code that it was simply wrong in the first place.

---
 xen/arch/x86/mm/p2m-pt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/mm/p2m-pt.c +1 -1
index 302b621..a1d5650 100644
@@ -691,7 +691,7 @@ static void p2m_change_type_global(struct p2m_domain *p2m,
                 l1mfn = _mfn(l2e_get_pfn(l2e[i2]));
                 l1e = map_domain_page(mfn_x(l1mfn));
 
-                for ( i1 = 0; i1 < L1_PAGETABLE_ENTRIES; i1++, gfn++ )
+                for ( i1 = 0; i1 < L1_PAGETABLE_ENTRIES; i1++ )
                 {
                     flags = l1e_get_flags(l1e[i1]);
                     if ( p2m_flags_to_type(flags) != ot )
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Andrew Cooper

Discovered by Coverity, CID 1056101

When taking the continue branch on the first iteration of the loop, gfn would
indeed be uninitialised when incremented. However, as gfn is unconditionally
constructed from i{1..4} before use in the loop body, having it incremented in
the loop header is useless.

Quoted 3 lines

Therefore, simply remove it.

Quoted 2 lines

I have compile tested this but not functionally tested it. It is fairly obvious from the code that it was simply wrong in the first place.

Indeed, or else the similar L2 and L3 loops would also have needed some form of increment.

Jan

#2 lore raw
In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper

Discovered by Coverity, CID 1056101

When taking the continue branch on the first iteration of the loop, gfn would indeed be uninitialised when incremented. However, as gfn is unconditionally constructed from i{1..4} before use in the loop body, having it incremented in the loop header is useless.

Therefore, simply remove it.

Acked + applied, thanks.

Tim.