Subject: Re: Memory Mapping a char array in User Space

From: David Howells <[email-masked]>
Date: Mon, 26 Jul 2010 20:42:01 +0100

Ravi Gupta <[email-masked]> wrote:

> My device gets memory map successfully but when I tried to read from it
> I get garbage value. Is there something that I am missing?

For starters, you really should allocate a page for your buffer rather than
using kernel static data.  mmap() allows access to page-aligned data through
multiple-of-page-sized holes only[*].  Not only that, your kernel static map
buffer may not necessarily have a struct page covering it, in which case
virt_to_page() may not give you anything useful.

Furthermore, I don't think *you* should be calling remap_pfn_range().
I think you should be leaving the mapping to the core VM routines.

David

[*] unless your kernel is CONFIG_MMU=n