diff options
Diffstat (limited to 'drivers/char/mem.c')
-rw-r--r-- | drivers/char/mem.c | 125 |
1 files changed, 17 insertions, 108 deletions
diff --git a/drivers/char/mem.c b/drivers/char/mem.c index bbee97ff355..64551ab6be0 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -625,65 +625,10 @@ static ssize_t splice_write_null(struct pipe_inode_info *pipe,struct file *out, return splice_from_pipe(pipe, out, ppos, len, flags, pipe_to_null); } -#ifdef CONFIG_MMU -/* - * For fun, we are using the MMU for this. - */ -static inline size_t read_zero_pagealigned(char __user * buf, size_t size) -{ - struct mm_struct *mm; - struct vm_area_struct * vma; - unsigned long addr=(unsigned long)buf; - - mm = current->mm; - /* Oops, this was forgotten before. -ben */ - down_read(&mm->mmap_sem); - - /* For private mappings, just map in zero pages. */ - for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) { - unsigned long count; - - if (vma->vm_start > addr || (vma->vm_flags & VM_WRITE) == 0) - goto out_up; - if (vma->vm_flags & (VM_SHARED | VM_HUGETLB)) - break; - count = vma->vm_end - addr; - if (count > size) - count = size; - - zap_page_range(vma, addr, count, NULL); - if (zeromap_page_range(vma, addr, count, PAGE_COPY)) - break; - - size -= count; - buf += count; - addr += count; - if (size == 0) - goto out_up; - } - - up_read(&mm->mmap_sem); - - /* The shared case is hard. Let's do the conventional zeroing. */ - do { - unsigned long unwritten = clear_user(buf, PAGE_SIZE); - if (unwritten) - return size + unwritten - PAGE_SIZE; - cond_resched(); - buf += PAGE_SIZE; - size -= PAGE_SIZE; - } while (size); - - return size; -out_up: - up_read(&mm->mmap_sem); - return size; -} - static ssize_t read_zero(struct file * file, char __user * buf, size_t count, loff_t *ppos) { - unsigned long left, unwritten, written = 0; + size_t written; if (!count) return 0; @@ -691,69 +636,33 @@ static ssize_t read_zero(struct file * file, char __user * buf, if (!access_ok(VERIFY_WRITE, buf, count)) return -EFAULT; - left = count; - - /* do we want to be clever? Arbitrary cut-off */ - if (count >= PAGE_SIZE*4) { - unsigned long partial; + written = 0; + while (count) { + unsigned long unwritten; + size_t chunk = count; - /* How much left of the page? */ - partial = (PAGE_SIZE-1) & -(unsigned long) buf; - unwritten = clear_user(buf, partial); - written = partial - unwritten; - if (unwritten) - goto out; - left -= partial; - buf += partial; - unwritten = read_zero_pagealigned(buf, left & PAGE_MASK); - written += (left & PAGE_MASK) - unwritten; + if (chunk > PAGE_SIZE) + chunk = PAGE_SIZE; /* Just for latency reasons */ + unwritten = clear_user(buf, chunk); + written += chunk - unwritten; if (unwritten) - goto out; - buf += left & PAGE_MASK; - left &= ~PAGE_MASK; - } - unwritten = clear_user(buf, left); - written += left - unwritten; -out: - return written ? written : -EFAULT; -} - -static int mmap_zero(struct file * file, struct vm_area_struct * vma) -{ - int err; - - if (vma->vm_flags & VM_SHARED) - return shmem_zero_setup(vma); - err = zeromap_page_range(vma, vma->vm_start, - vma->vm_end - vma->vm_start, vma->vm_page_prot); - BUG_ON(err == -EEXIST); - return err; -} -#else /* CONFIG_MMU */ -static ssize_t read_zero(struct file * file, char * buf, - size_t count, loff_t *ppos) -{ - size_t todo = count; - - while (todo) { - size_t chunk = todo; - - if (chunk > 4096) - chunk = 4096; /* Just for latency reasons */ - if (clear_user(buf, chunk)) - return -EFAULT; + break; buf += chunk; - todo -= chunk; + count -= chunk; cond_resched(); } - return count; + return written ? written : -EFAULT; } static int mmap_zero(struct file * file, struct vm_area_struct * vma) { +#ifndef CONFIG_MMU return -ENOSYS; +#endif + if (vma->vm_flags & VM_SHARED) + return shmem_zero_setup(vma); + return 0; } -#endif /* CONFIG_MMU */ static ssize_t write_full(struct file * file, const char __user * buf, size_t count, loff_t *ppos) |