btrfs: remove pointless and double ulist frees in error paths of qgroup tests
[platform/kernel/linux-rpi.git] / fs / coredump.c
index 64e2ce8..26eb5a0 100644 (file)
@@ -54,6 +54,7 @@
 #include <trace/events/sched.h>
 
 static bool dump_vma_snapshot(struct coredump_params *cprm);
+static void free_vma_snapshot(struct coredump_params *cprm);
 
 int core_uses_pid;
 unsigned int core_pipe_limit;
@@ -834,7 +835,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)
                        dump_emit(&cprm, "", 1);
                }
                file_end_write(cprm.file);
-               kvfree(cprm.vma_meta);
+               free_vma_snapshot(&cprm);
        }
        if (ispipe && core_pipe_limit)
                wait_for_dump_helpers(cprm.file);
@@ -1111,6 +1112,20 @@ static struct vm_area_struct *next_vma(struct vm_area_struct *this_vma,
        return gate_vma;
 }
 
+static void free_vma_snapshot(struct coredump_params *cprm)
+{
+       if (cprm->vma_meta) {
+               int i;
+               for (i = 0; i < cprm->vma_count; i++) {
+                       struct file *file = cprm->vma_meta[i].file;
+                       if (file)
+                               fput(file);
+               }
+               kvfree(cprm->vma_meta);
+               cprm->vma_meta = NULL;
+       }
+}
+
 /*
  * Under the mmap_lock, take a snapshot of relevant information about the task's
  * VMAs.
@@ -1147,15 +1162,14 @@ static bool dump_vma_snapshot(struct coredump_params *cprm)
                m->end = vma->vm_end;
                m->flags = vma->vm_flags;
                m->dump_size = vma_dump_size(vma, cprm->mm_flags);
-       }
-
-       mmap_write_unlock(mm);
+               m->pgoff = vma->vm_pgoff;
 
-       if (WARN_ON(i != cprm->vma_count)) {
-               kvfree(cprm->vma_meta);
-               return false;
+               m->file = vma->vm_file;
+               if (m->file)
+                       get_file(m->file);
        }
 
+       mmap_write_unlock(mm);
 
        for (i = 0; i < cprm->vma_count; i++) {
                struct core_vma_metadata *m = cprm->vma_meta + i;