drivers/char/mem.c: cleanups

- fix switch statement layout

- fix whitespace stuff

- fix comment layout

- remove unneeded inlining

- use __weak

- remove trailing whitespace

- move uncached_access() inside `#ifndef __HAVE_PHYS_MEM_ACCESS_PROT' - it
  is otherwise unused.

Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Andrew Morton
2010-03-10 15:21:52 -08:00
committed by Linus Torvalds
parent dcefafb6ac
commit d7d4d849b4

View File

@@ -44,36 +44,6 @@ static inline unsigned long size_inside_page(unsigned long start,
return min(sz, size); return min(sz, size);
} }
/*
* Architectures vary in how they handle caching for addresses
* outside of main memory.
*
*/
static inline int uncached_access(struct file *file, unsigned long addr)
{
#if defined(CONFIG_IA64)
/*
* On ia64, we ignore O_DSYNC because we cannot tolerate memory attribute aliases.
*/
return !(efi_mem_attributes(addr) & EFI_MEMORY_WB);
#elif defined(CONFIG_MIPS)
{
extern int __uncached_access(struct file *file,
unsigned long addr);
return __uncached_access(file, addr);
}
#else
/*
* Accessing memory above the top the kernel knows about or through a file pointer
* that was marked O_DSYNC will be done non-cached.
*/
if (file->f_flags & O_DSYNC)
return 1;
return addr >= __pa(high_memory);
#endif
}
#ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE #ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE
static inline int valid_phys_addr_range(unsigned long addr, size_t count) static inline int valid_phys_addr_range(unsigned long addr, size_t count)
{ {
@@ -115,7 +85,7 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
} }
#endif #endif
void __attribute__((weak)) unxlate_dev_mem_ptr(unsigned long phys, void *addr) void __weak unxlate_dev_mem_ptr(unsigned long phys, void *addr)
{ {
} }
@@ -157,9 +127,9 @@ static ssize_t read_mem(struct file * file, char __user * buf,
return -EPERM; return -EPERM;
/* /*
* On ia64 if a page has been mapped somewhere as * On ia64 if a page has been mapped somewhere as uncached, then
* uncached, then it must also be accessed uncached * it must also be accessed uncached by the kernel or data
* by the kernel or data corruption may occur * corruption may occur.
*/ */
ptr = xlate_dev_mem_ptr(p); ptr = xlate_dev_mem_ptr(p);
if (!ptr) if (!ptr)
@@ -212,9 +182,9 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
return -EPERM; return -EPERM;
/* /*
* On ia64 if a page has been mapped somewhere as * On ia64 if a page has been mapped somewhere as uncached, then
* uncached, then it must also be accessed uncached * it must also be accessed uncached by the kernel or data
* by the kernel or data corruption may occur * corruption may occur.
*/ */
ptr = xlate_dev_mem_ptr(p); ptr = xlate_dev_mem_ptr(p);
if (!ptr) { if (!ptr) {
@@ -242,13 +212,46 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
return written; return written;
} }
int __attribute__((weak)) phys_mem_access_prot_allowed(struct file *file, int __weak phys_mem_access_prot_allowed(struct file *file,
unsigned long pfn, unsigned long size, pgprot_t *vma_prot) unsigned long pfn, unsigned long size, pgprot_t *vma_prot)
{ {
return 1; return 1;
} }
#ifndef __HAVE_PHYS_MEM_ACCESS_PROT #ifndef __HAVE_PHYS_MEM_ACCESS_PROT
/*
* Architectures vary in how they handle caching for addresses
* outside of main memory.
*
*/
static int uncached_access(struct file *file, unsigned long addr)
{
#if defined(CONFIG_IA64)
/*
* On ia64, we ignore O_DSYNC because we cannot tolerate memory
* attribute aliases.
*/
return !(efi_mem_attributes(addr) & EFI_MEMORY_WB);
#elif defined(CONFIG_MIPS)
{
extern int __uncached_access(struct file *file,
unsigned long addr);
return __uncached_access(file, addr);
}
#else
/*
* Accessing memory above the top the kernel knows about or through a
* file pointer
* that was marked O_DSYNC will be done non-cached.
*/
if (file->f_flags & O_DSYNC)
return 1;
return addr >= __pa(high_memory);
#endif
}
static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
unsigned long size, pgprot_t vma_prot) unsigned long size, pgprot_t vma_prot)
{ {
@@ -337,9 +340,9 @@ static int mmap_kmem(struct file * file, struct vm_area_struct * vma)
pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT; pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT;
/* /*
* RED-PEN: on some architectures there is more mapped memory * RED-PEN: on some architectures there is more mapped memory than
* than available in mem_map which pfn_valid checks * available in mem_map which pfn_valid checks for. Perhaps should add a
* for. Perhaps should add a new macro here. * new macro here.
* *
* RED-PEN: vmalloc is not supported right now. * RED-PEN: vmalloc is not supported right now.
*/ */
@@ -465,8 +468,7 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
} }
static inline ssize_t static ssize_t do_write_kmem(unsigned long p, const char __user *buf,
do_write_kmem(unsigned long p, const char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
ssize_t written, sz; ssize_t written, sz;
@@ -491,9 +493,9 @@ do_write_kmem(unsigned long p, const char __user *buf,
sz = size_inside_page(p, count); sz = size_inside_page(p, count);
/* /*
* On ia64 if a page has been mapped somewhere as * On ia64 if a page has been mapped somewhere as uncached, then
* uncached, then it must also be accessed uncached * it must also be accessed uncached by the kernel or data
* by the kernel or data corruption may occur * corruption may occur.
*/ */
ptr = xlate_dev_kmem_ptr((char *)p); ptr = xlate_dev_kmem_ptr((char *)p);
@@ -514,7 +516,6 @@ do_write_kmem(unsigned long p, const char __user *buf,
return written; return written;
} }
/* /*
* This function writes to the *virtual* memory as seen by the kernel. * This function writes to the *virtual* memory as seen by the kernel.
*/ */
@@ -688,7 +689,6 @@ static ssize_t write_full(struct file * file, const char __user * buf,
* can fopen() both devices with "a" now. This was previously impossible. * can fopen() both devices with "a" now. This was previously impossible.
* -- SRB. * -- SRB.
*/ */
static loff_t null_lseek(struct file *file, loff_t offset, int orig) static loff_t null_lseek(struct file *file, loff_t offset, int orig)
{ {
return file->f_pos = 0; return file->f_pos = 0;