Skip to contentSkip to conversation

x86/mm: Simplify expression in set_gpfn_from_mfn()

PATCH In review Andrew Cooper 2 participants 2 messages Sep 15, 2020 – Sep 16, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm: Simplify expression in set_gpfn_from_mfn()

Coverity points out that the "d &&" is redundant.

Fixes c9476c4ad72 ("x86: don't override INVALID_M2P_ENTRY with SHARED_M2P_ENTRY")

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/x86_64/mm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/x86_64/mm.c +1 -1
index 0d1aadbfce..4c0a3a275c 100644
@@ -1336,7 +1336,7 @@ void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
     {
         const struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
 
-        if ( d && (d == dom_cow) )
+        if ( d == dom_cow )
             entry = SHARED_M2P_ENTRY;
     }
 
Signature · 1 line
2.11.0
#1 lore raw
Quoted 1 line · Andrew Cooper

Coverity points out that the "d &&" is redundant.

How can it know that ...

xen/arch/x86/x86_64/mm.c void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn) · line 1339

Quoted 8 lines
xen/arch/x86/x86_64/mm.c +1 -1
@@ -1336,7 +1336,7 @@ void set_gpfn_from_mfn(unsigned long mfn, unsigned long pfn)
     {
         const struct domain *d = page_get_owner(mfn_to_page(_mfn(mfn)));
 
-        if ( d && (d == dom_cow) )
+        if ( d == dom_cow )

... dom_cow is not NULL (in which case the new expression is wrong when d also is). I actually think Coverity has spotted the issue when dom_cow is #define-d to NULL, in which case the original expression degenerates to "d && !d".

If the purpose of the extra check is more obvious that way, we could check dom_cow to be non-NULL (instead of d), but I'm afraid this may not silence Coverity.

Jan