Skip to content

Commit 95faf69

Browse files
committed
mm: make vm_area_dup() actually copy the old vma data
.. and re-initialize th eanon_vma_chain head. This removes some boiler-plate from the users, and also makes it clear why it didn't need use the 'zalloc()' version. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 3928d4f commit 95faf69

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

kernel/fork.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,13 @@ struct vm_area_struct *vm_area_alloc(void)
315315

316316
struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig)
317317
{
318-
return kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
318+
struct vm_area_struct *new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
319+
320+
if (new) {
321+
*new = *orig;
322+
INIT_LIST_HEAD(&new->anon_vma_chain);
323+
}
324+
return new;
319325
}
320326

321327
void vm_area_free(struct vm_area_struct *vma)
@@ -473,8 +479,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
473479
tmp = vm_area_dup(mpnt);
474480
if (!tmp)
475481
goto fail_nomem;
476-
*tmp = *mpnt;
477-
INIT_LIST_HEAD(&tmp->anon_vma_chain);
478482
retval = vma_dup_policy(mpnt, tmp);
479483
if (retval)
480484
goto fail_nomem_policy;

mm/mmap.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,11 +2624,6 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
26242624
if (!new)
26252625
return -ENOMEM;
26262626

2627-
/* most fields are the same, copy all, and then fixup */
2628-
*new = *vma;
2629-
2630-
INIT_LIST_HEAD(&new->anon_vma_chain);
2631-
26322627
if (new_below)
26332628
new->vm_end = addr;
26342629
else {
@@ -3205,13 +3200,11 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
32053200
new_vma = vm_area_dup(vma);
32063201
if (!new_vma)
32073202
goto out;
3208-
*new_vma = *vma;
32093203
new_vma->vm_start = addr;
32103204
new_vma->vm_end = addr + len;
32113205
new_vma->vm_pgoff = pgoff;
32123206
if (vma_dup_policy(vma, new_vma))
32133207
goto out_free_vma;
3214-
INIT_LIST_HEAD(&new_vma->anon_vma_chain);
32153208
if (anon_vma_clone(new_vma, vma))
32163209
goto out_free_mempol;
32173210
if (new_vma->vm_file)

mm/nommu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,6 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
14761476
}
14771477

14781478
/* most fields are the same, copy all, and then fixup */
1479-
*new = *vma;
14801479
*region = *vma->vm_region;
14811480
new->vm_region = region;
14821481

0 commit comments

Comments
 (0)