* [PATCH 1/1] mm/vmalloc.c: eliminate extra loop in pcpu_get_vm_areas error path
@ 2011-11-18 11:43 Kautuk Consul
2011-11-18 19:59 ` Andrew Morton
0 siblings, 1 reply; 4+ messages in thread
From: Kautuk Consul @ 2011-11-18 11:43 UTC (permalink / raw)
To: Andrew Morton, Joe Perches, David Rientjes, Minchan Kim,
Paul E. McKenney
Cc: linux-mm, linux-kernel, Kautuk Consul
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.
Signed-off-by: Kautuk Consul <consul.kautuk@gmail.com>
---
mm/vmalloc.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index b669aa6..1a0d4e2 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -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;
--
1.7.6
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. 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:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/1] mm/vmalloc.c: eliminate extra loop in pcpu_get_vm_areas error path
2011-11-18 11:43 [PATCH 1/1] mm/vmalloc.c: eliminate extra loop in pcpu_get_vm_areas error path Kautuk Consul
@ 2011-11-18 19:59 ` Andrew Morton
2011-11-19 3:32 ` kautuk.c @samsung.com
2011-11-23 5:34 ` David Rientjes
0 siblings, 2 replies; 4+ messages in thread
From: Andrew Morton @ 2011-11-18 19:59 UTC (permalink / raw)
To: Kautuk Consul
Cc: Joe Perches, David Rientjes, Minchan Kim, Paul E. McKenney,
linux-mm, linux-kernel
On Fri, 18 Nov 2011 17:13:50 +0530
Kautuk Consul <consul.kautuk@gmail.com> wrote:
> 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.
>
> Signed-off-by: Kautuk Consul <consul.kautuk@gmail.com>
> ---
> mm/vmalloc.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index b669aa6..1a0d4e2 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -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;
Which means we can also do the below, yes? (please check my homework!)
--- a/mm/vmalloc.c~mm-vmallocc-eliminate-extra-loop-in-pcpu_get_vm_areas-error-path-fix
+++ a/mm/vmalloc.c
@@ -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);
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. 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:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/1] mm/vmalloc.c: eliminate extra loop in pcpu_get_vm_areas error path
2011-11-18 19:59 ` Andrew Morton
@ 2011-11-19 3:32 ` kautuk.c @samsung.com
2011-11-23 5:34 ` David Rientjes
1 sibling, 0 replies; 4+ messages in thread
From: kautuk.c @samsung.com @ 2011-11-19 3:32 UTC (permalink / raw)
To: Andrew Morton
Cc: Joe Perches, David Rientjes, Minchan Kim, Paul E. McKenney,
linux-mm, linux-kernel
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.
On Fri, Nov 18, 2011 at 2:59 PM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Fri, 18 Nov 2011 17:13:50 +0530
> Kautuk Consul <consul.kautuk@gmail.com> wrote:
>
>> 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.
>>
>> Signed-off-by: Kautuk Consul <consul.kautuk@gmail.com>
>> ---
>> mm/vmalloc.c | 3 ++-
>> 1 files changed, 2 insertions(+), 1 deletions(-)
>>
>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>> index b669aa6..1a0d4e2 100644
>> --- a/mm/vmalloc.c
>> +++ b/mm/vmalloc.c
>> @@ -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;
>
> Which means we can also do the below, yes? (please check my homework!)
>
> --- a/mm/vmalloc.c~mm-vmallocc-eliminate-extra-loop-in-pcpu_get_vm_areas-error-path-fix
> +++ a/mm/vmalloc.c
> @@ -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);
> _
>
>
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. 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:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/1] mm/vmalloc.c: eliminate extra loop in pcpu_get_vm_areas error path
2011-11-18 19:59 ` Andrew Morton
2011-11-19 3:32 ` kautuk.c @samsung.com
@ 2011-11-23 5:34 ` David Rientjes
1 sibling, 0 replies; 4+ messages in thread
From: David Rientjes @ 2011-11-23 5:34 UTC (permalink / raw)
To: Andrew Morton
Cc: Kautuk Consul, Joe Perches, Minchan Kim, Paul E. McKenney,
linux-mm, linux-kernel
On Fri, 18 Nov 2011, Andrew Morton wrote:
> > 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.
> >
> > Signed-off-by: Kautuk Consul <consul.kautuk@gmail.com>
> > ---
> > mm/vmalloc.c | 3 ++-
> > 1 files changed, 2 insertions(+), 1 deletions(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index b669aa6..1a0d4e2 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -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;
>
> Which means we can also do the below, yes? (please check my homework!)
>
> --- a/mm/vmalloc.c~mm-vmallocc-eliminate-extra-loop-in-pcpu_get_vm_areas-error-path-fix
> +++ a/mm/vmalloc.c
> @@ -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);
On both patches:
Acked-by: David Rientjes <rientjes@google.com>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. 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:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-11-23 5:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-18 11:43 [PATCH 1/1] mm/vmalloc.c: eliminate extra loop in pcpu_get_vm_areas error path Kautuk Consul
2011-11-18 19:59 ` Andrew Morton
2011-11-19 3:32 ` kautuk.c @samsung.com
2011-11-23 5:34 ` David Rientjes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox