Commit f1db7afd917e54711798c64d78f8f5fb090f950d

Authored by Kautuk Consul
Committed by Linus Torvalds
1 parent 3f79768f23

mm/vmalloc.c: eliminate extra loop in pcpu_get_vm_areas error path

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.

[akpm@linux-foundation.org: remove now-unneeded tests]
Signed-off-by: Kautuk Consul <consul.kautuk@gmail.com>
Acked-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 4 additions and 5 deletions Side-by-side Diff

... ... @@ -2378,7 +2378,7 @@
2378 2378 vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
2379 2379 vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
2380 2380 if (!vas || !vms)
2381   - goto err_free;
  2381 + goto err_free2;
2382 2382  
2383 2383 for (area = 0; area < nr_vms; area++) {
2384 2384 vas[area] = kzalloc(sizeof(struct vmap_area), GFP_KERNEL);
2385 2385  
... ... @@ -2476,11 +2476,10 @@
2476 2476  
2477 2477 err_free:
2478 2478 for (area = 0; area < nr_vms; area++) {
2479   - if (vas)
2480   - kfree(vas[area]);
2481   - if (vms)
2482   - kfree(vms[area]);
  2479 + kfree(vas[area]);
  2480 + kfree(vms[area]);
2483 2481 }
  2482 +err_free2:
2484 2483 kfree(vas);
2485 2484 kfree(vms);
2486 2485 return NULL;