DEBUG_VIRTUAL, ensures that when __pa() is only called on
addresses for which its results are correct.  For everything
else, we BUG_ON().

This changes the /dev/kmem ordering so that we check pfn_valid()
_before_ we call __pa().  This ensures we're not calling __pa()
with gibberish and avoids the BUG_ON() in those cases, instead
returning the error to userspace _before_ the __pa() call.



Signed-off-by: Dave Hansen <dave.han...@linux.intel.com>
---

 linux.git-davehans/drivers/char/mem.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff -puN drivers/char/mem.c~make-devmem-work-on-highmem3a drivers/char/mem.c
--- linux.git/drivers/char/mem.c~make-devmem-work-on-highmem3a  2013-04-10 
16:23:45.361087291 -0700
+++ linux.git-davehans/drivers/char/mem.c       2013-04-10 16:23:45.365087295 
-0700
@@ -347,9 +347,6 @@ static int mmap_kmem(struct file *file,
         */
        if (kernel_vaddr >= high_memory)
                return -EIO;
-       /* Turn a kernel-virtual address into a physical page frame */
-       pfn = __pa(kernel_vaddr) >> PAGE_SHIFT;
-
        /*
         * RED-PEN: on some architectures there is more mapped memory than
         * available in mem_map which pfn_valid checks for. Perhaps should add a
@@ -360,6 +357,9 @@ static int mmap_kmem(struct file *file,
        if (!pfn_valid(pfn))
                return -EIO;
 
+       /* Turn a kernel-virtual address into a physical page frame */
+       pfn = __pa(kernel_vaddr) >> PAGE_SHIFT;
+
        vma->vm_pgoff = pfn;
        return mmap_mem(file, vma);
 }
_
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to