thanks Adrian - i've queued up the fix below.
Venkatesh, the code flow in reserve_memtype() is still as simple as it
could be i believe - and the code flow complication directly resulted in
this bug.
For example we should never pass in a NULL flags pointer - that way we
could get rid of the NULL pointer checking - just fill in the return
value unconditionally and just dont use it in the return site if not
needed.
Another area to improve would be to merge the return code and the flags
value - i.e. to not pass in a return value pointer at all. All
_PAGE_CACHE_* flags are positive integers, so using negatives as a
failure condition would still be OK. The special '-1 == wildcard'
meaning for flags could still be kept. Hm?
Ingo
-------------------->
Subject: x86: PAT fix
From: Ingo Molnar <mingo@elte.hu>
Date: Fri Mar 21 15:42:28 CET 2008
Adrian Bunk noticed the following Coverity report:
the fix simplifies the code as we get rid of the 'ret_flags'
complication.
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/mm/pat.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
Index: linux-x86.q/arch/x86/mm/pat.c
===================================================================
--- linux-x86.q.orig/arch/x86/mm/pat.c
+++ linux-x86.q/arch/x86/mm/pat.c
@@ -510,7 +510,6 @@ int phys_mem_access_prot_allowed(struct
{
u64 offset = ((u64) pfn) << PAGE_SHIFT;
unsigned long flags = _PAGE_CACHE_UC_MINUS;
- unsigned long ret_flags;
int retval;
if (!range_is_allowed(pfn, size))
@@ -549,14 +548,12 @@ int phys_mem_access_prot_allowed(struct
if (flags != _PAGE_CACHE_UC_MINUS) {
retval = reserve_memtype(offset, offset + size, flags, NULL);
} else {
- retval = reserve_memtype(offset, offset + size, -1, &ret_flags);
+ retval = reserve_memtype(offset, offset + size, -1, &flags);
}
if (retval < 0)
return 0;
- flags = ret_flags;
-
if (pfn <= max_pfn_mapped &&
ioremap_change_attr((unsigned long)__va(offset), size, flags) < 0) {
free_memtype(offset, offset + size);
--