mm/vmalloc.c: eliminate extra loop in pcpu_get_vm_areas error path
Subsystems (2)
PATCH 1/1 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.
--- mm/vmalloc.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
mm/vmalloc.c +2 -1
@@ -2352,7 +2352,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 );
@@ -2455,6 +2455,7 @@ err_free:if (vms)kfree (vms[area]); } +err_free2:kfree (vas);kfree (vms);return NULL ;
Signature · 8 lines
1.7.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Andrew Morton
maintainerQuoted 30 lines · On Fri, 18 Nov 2011 17:13:50 +0530 Kautuk Consul <[email protected]>…
If either of the vas or vms arrays are not properly kzalloced, then the code jumps to the
err_freelabel.The
err_freelabel 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_free2and then jumping to it.Signed-off-by Kautuk Consul <[email protected]>--- mm/vmalloc.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)mm/vmalloc.c +1
-1@@ -2352,7 +2352,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 );
mm/vmalloc.c err_free: · line 2461
Quoted 7 lines
mm/vmalloc.c +1
-0@@ -2455,6 +2455,7 @@ err_free:if (vms)kfree (vms[area]); } +err_free2:kfree (vas);kfree (vms);return NULL ;
Which means we can also do the below, yes? (please check my homework!)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmallocc-eliminate-extra-loop-in-pcpu_get_vm_areas-error-path-fix +2 -4
@@ -2449,10 +2449,8 @@ found: 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);
_
Oh yes, I missed that out. :)
We should also do that.
Do you need me to redo this patch with this change ? Although, I do notice that you seem to have already accepted this patch.
Quoted 62 lines · Andrew Morton
Quoted 30 lines · On Fri, 18 Nov 2011 17:13:50 +0530 Kautuk Consul <[email protected]>…
If either of the vas or vms arrays are not properly kzalloced, then the code jumps to the
err_freelabel.The
err_freelabel 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_free2and then jumping to it.Signed-off-by Kautuk Consul <[email protected]>---
mm/vmalloc.c | 3 ++-1 files changed, 2 insertions(+), 1 deletions(-)mm/vmalloc.c +1
-1@@ -2352,7 +2352,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);mm/vmalloc.c err_free: · line 2461
Quoted 7 lines
mm/vmalloc.c +1
-0@@ -2455,6 +2455,7 @@ err_free: if (vms) kfree(vms[area]); } +err_free2: kfree(vas); kfree(vms); return NULL;Which means we can also do the below, yes? (please check my homework!)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmallocc-eliminate-extra-loop-in-pcpu_get_vm_areas-error-path-fix +0
-0@@ -2449,10 +2449,8 @@ found: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);
_
David Rientjes
Acked-byQuoted 45 lines · Andrew Morton
Quoted 30 lines
If either of the vas or vms arrays are not properly kzalloced, then the code jumps to the
err_freelabel.The
err_freelabel 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_free2and then jumping to it.Signed-off-by Kautuk Consul <[email protected]>--- mm/vmalloc.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)mm/vmalloc.c +1
-1@@ -2352,7 +2352,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 );mm/vmalloc.c err_free: · line 2461
Quoted 7 lines
mm/vmalloc.c +1
-0@@ -2455,6 +2455,7 @@ err_free:if (vms)kfree (vms[area]); } +err_free2:kfree (vas);kfree (vms);return NULL ;Which means we can also do the below, yes? (please check my homework!)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmallocc-eliminate-extra-loop-in-pcpu_get_vm_areas-error-path-fix +0
-0@@ -2449,10 +2449,8 @@ found: err_free:
mm/vmalloc.c found: · line 2456
Quoted 10 lines
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmallocc-eliminate-extra-loop-in-pcpu_get_vm_areas-error-path-fix +2
-4for (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);
On both patches: