Skip to contentSkip to conversation

arch: ia64: kernel: perfmon: Check return value of insert_vm_struct()

PATCH In review Chen Gang 2 participants 2 messages Aug 23, 2015 – Sep 4, 2015

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 arch: ia64: kernel: perfmon: Check return value of insert_vm_struct()

In pfm_smpl_buffer_alloc, insert_vm_struct may also return -ENOMEM, so need check it too.

And insert_vm_struct needn't consider about pfm_remap_buffer in failure process ("goto error" is enough):

 - pfm_remap_buffer doen't consider about remap_pfn_range.

 - It is about the relationship between vma and smpl_buf.

 - SO if both vma and smpl_buf are released ("goto error"), all things are OK.

---
 arch/ia64/kernel/perfmon.c | 6 +++++-

 1 file changed, 5 insertions(+), 1 deletion(-)
arch/ia64/kernel/perfmon.c +0 -0
index 60e02f7..ae77946 100644
@@ -2330,7 +2330,11 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t

  * now insert the vma in the vm list for the process, must be
  * done with mmap lock held
  */
- insert_vm_struct(mm, vma);
+ if (insert_vm_struct(mm, vma)) {
+ DPRINT(("Can't insert vm structure.\n"));
+ up_write(&task->mm->mmap_sem);
+ goto error;
+ }

  vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file, vma_pages(vma)); --

#1 lore raw

Hello Maintainers:

Please help check this patch when you have time.

Thanks.

Quoted 39 lines · Chen Gang

In pfm_smpl_buffer_alloc, insert_vm_struct may also return -ENOMEM, so need check it too.

And insert_vm_struct needn't consider about pfm_remap_buffer in failure process ("goto error" is enough):

- pfm_remap_buffer doen't consider about remap_pfn_range.

- It is about the relationship between vma and smpl_buf.

- SO if both vma and smpl_buf are released ("goto error"), all things are OK.

---
 arch/ia64/kernel/perfmon.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/ia64/kernel/perfmon.c +5 -1
index 60e02f7..ae77946 100644
@@ -2330,7 +2330,11 @@ pfm_smpl_buffer_alloc(struct task_struct *task, struct file *filp, pfm_context_t
 	 * now insert the vma in the vm list for the process, must be
 	 * done with mmap lock held
 	 */
-	insert_vm_struct(mm, vma);
+	if (insert_vm_struct(mm, vma)) {
+		DPRINT(("Can't insert vm structure.\n"));
+		up_write(&task->mm->mmap_sem);
+		goto error;
+	}
 
 	vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file,
 							vma_pages(vma));
Signature · 3 lines
Chen Gang (陈刚)

Open, share, and attitude like air, water, and life which God blessed