]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
vmcore-support-mmap-on-proc-vmcore-fix
authorAndrew Morton <akpm@linux-foundation.org>
Fri, 7 Jun 2013 00:07:51 +0000 (10:07 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 7 Jun 2013 05:42:13 +0000 (15:42 +1000)
use min(), switch to conventional error-unwinding approach

Cc: Atsushi Kumagai <kumagai-atsushi@mxc.nes.nec.co.jp>
Cc: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Lisa Mitchell <lisa.mitchell@hp.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Zhang Yanfei <zhangyanfei@cn.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/proc/vmcore.c

index 423796979640b75d782fc989191a80dae672e2b1..0f6db5269d38159982d25ef88909dfe2bf021b77 100644 (file)
@@ -218,9 +218,7 @@ static int mmap_vmcore(struct file *file, struct vm_area_struct *vma)
        if (start < elfcorebuf_sz) {
                u64 pfn;
 
-               tsz = elfcorebuf_sz - start;
-               if (size < tsz)
-                       tsz = size;
+               tsz = min(elfcorebuf_sz - (size_t)start, size);
                pfn = __pa(elfcorebuf + start) >> PAGE_SHIFT;
                if (remap_pfn_range(vma, vma->vm_start, pfn, tsz,
                                    vma->vm_page_prot))
@@ -236,15 +234,11 @@ static int mmap_vmcore(struct file *file, struct vm_area_struct *vma)
        if (start < elfcorebuf_sz + elfnotes_sz) {
                void *kaddr;
 
-               tsz = elfcorebuf_sz + elfnotes_sz - start;
-               if (size < tsz)
-                       tsz = size;
+               tsz = min(elfcorebuf_sz + elfnotes_sz - (size_t)start, size);
                kaddr = elfnotes_buf + start - elfcorebuf_sz;
                if (remap_vmalloc_range_partial(vma, vma->vm_start + len,
-                                               kaddr, tsz)) {
-                       do_munmap(vma->vm_mm, vma->vm_start, len);
-                       return -EAGAIN;
-               }
+                                               kaddr, tsz))
+                       goto fail;
                size -= tsz;
                start += tsz;
                len += tsz;
@@ -257,16 +251,12 @@ static int mmap_vmcore(struct file *file, struct vm_area_struct *vma)
                if (start < m->offset + m->size) {
                        u64 paddr = 0;
 
-                       tsz = m->offset + m->size - start;
-                       if (size < tsz)
-                               tsz = size;
+                       tsz = min_t(size_t, m->offset + m->size - start, size);
                        paddr = m->paddr + start - m->offset;
                        if (remap_pfn_range(vma, vma->vm_start + len,
                                            paddr >> PAGE_SHIFT, tsz,
-                                           vma->vm_page_prot)) {
-                               do_munmap(vma->vm_mm, vma->vm_start, len);
-                               return -EAGAIN;
-                       }
+                                           vma->vm_page_prot))
+                               goto fail;
                        size -= tsz;
                        start += tsz;
                        len += tsz;
@@ -277,6 +267,9 @@ static int mmap_vmcore(struct file *file, struct vm_area_struct *vma)
        }
 
        return 0;
+fail:
+       do_munmap(vma->vm_mm, vma->vm_start, len);
+       return -EAGAIN;
 }
 
 static const struct file_operations proc_vmcore_operations = {