Skip to content

Commit

Permalink
mm/vmalloc.c: eliminate extra loop in pcpu_get_vm_areas error path
Browse files Browse the repository at this point in the history
If either of the vas or vms arrays are not properly kzalloced, then the
code jumps to the err_free label.

The err_free label runs a loop to check and free each of the array members
of the vas and vms arrays which is not required for this situation as none
of the array members have been allocated till this point.

Eliminate the extra loop we have to go through by introducing a new label
err_free2 and then jumping to it.

[[email protected]: remove now-unneeded tests]
Signed-off-by: Kautuk Consul <[email protected]>
Acked-by: David Rientjes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Kautuk Consul authored and torvalds committed Jan 13, 2012
1 parent 3f79768 commit f1db7af
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mm/vmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
if (!vas || !vms)
goto err_free;
goto err_free2;

for (area = 0; area < nr_vms; area++) {
vas[area] = kzalloc(sizeof(struct vmap_area), GFP_KERNEL);
Expand Down Expand Up @@ -2476,11 +2476,10 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,

err_free:
for (area = 0; area < nr_vms; area++) {
if (vas)
kfree(vas[area]);
if (vms)
kfree(vms[area]);
kfree(vas[area]);
kfree(vms[area]);
}
err_free2:
kfree(vas);
kfree(vms);
return NULL;
Expand Down

0 comments on commit f1db7af

Please sign in to comment.