Skip to contentSkip to conversation

sched: fix double kfree

PATCH Applied Li Zefan 5 participants 7 messages Jan 6, 2009 – Jan 7, 2009

lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 sched: fix double kfree

Impact: fix double kfree in failure path

It's not the responsibility of init_rootdomain() to free root_domain allocated by alloc_rootdomain().

---
 kernel/sched.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kernel/sched.c +2 -3
index 545c6fc..2bad712 100644
@@ -6970,7 +6970,7 @@ static int init_rootdomain(struct root_domain *rd, bool bootmem)
 	}
 
 	if (!alloc_cpumask_var(&rd->span, GFP_KERNEL))
-		goto free_rd;
+		goto out;
 	if (!alloc_cpumask_var(&rd->online, GFP_KERNEL))
 		goto free_span;
 	if (!alloc_cpumask_var(&rd->rto_mask, GFP_KERNEL))
@@ -6986,8 +6986,7 @@ free_online:
 	free_cpumask_var(rd->online);
 free_span:
 	free_cpumask_var(rd->span);
-free_rd:
-	kfree(rd);
+out:
 	return -ENOMEM;
 }
 
Signature · 1 line
1.5.4.rc3
Applied
#1 lore raw
Quoted 9 lines · Li Zefan

Impact: fix double kfree in failure path

It's not the responsibility of init_rootdomain() to free root_domain allocated by alloc_rootdomain().

---
 kernel/sched.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

applied to tip/sched/urgent, thanks!

Ingo

Reviewed-by on v1 1/1
#2 lore raw
In reply to Li Zefan
Quoted 6 lines · Li Zefan

Impact: fix double kfree in failure path

It's not the responsibility of init_rootdomain() to free root_domain allocated by alloc_rootdomain().

FWIW

Quoted 36 lines
---
 kernel/sched.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kernel/sched.c +2 -4
index 545c6fc..2bad712 100644
@@ -6970,7 +6970,7 @@ static int init_rootdomain(struct root_domain *rd, bool bootmem)
       }
 
       if (!alloc_cpumask_var(&rd->span, GFP_KERNEL))
-               goto free_rd;
+               goto out;
       if (!alloc_cpumask_var(&rd->online, GFP_KERNEL))
               goto free_span;
       if (!alloc_cpumask_var(&rd->rto_mask, GFP_KERNEL))
@@ -6986,8 +6986,7 @@ free_online:
       free_cpumask_var(rd->online);
 free_span:
       free_cpumask_var(rd->span);
-free_rd:
-       kfree(rd);
+out:
       return -ENOMEM;
 }
 
--

1.5.4.rc3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#4 lore raw
In reply to Li Zefan
Quoted 6 lines · On Tuesday 06 January 2009 20:09:06 Li Zefan wrote:

Impact: fix double kfree in failure path

It's not the responsibility of init_rootdomain() to free root_domain allocated by alloc_rootdomain().

Thanks, you're right.

Good catch!
Rusty.

#5 lore raw
In reply to Li Zefan
Quoted 24 lines · Li Zefan

Impact: fix double kfree in failure path

It's not the responsibility of init_rootdomain() to free root_domain allocated by alloc_rootdomain().

---
 kernel/sched.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kernel/sched.c +1 -1
index 545c6fc..2bad712 100644
@@ -6970,7 +6970,7 @@ static int init_rootdomain(struct root_domain *rd, bool bootmem)
 	}
 
 	if (!alloc_cpumask_var(&rd->span, GFP_KERNEL))
-		goto free_rd;
+		goto out;
 	if (!alloc_cpumask_var(&rd->online, GFP_KERNEL))
 		goto free_span;
 	if (!alloc_cpumask_var(&rd->rto_mask, GFP_KERNEL))

kernel/sched.c free_online: · line 6992

Quoted 9 lines
kernel/sched.c +1 -2
@@ -6986,8 +6986,7 @@ free_online:
 	free_cpumask_var(rd->online);
 free_span:
 	free_cpumask_var(rd->span);
-free_rd:
-	kfree(rd);
+out:
 	return -ENOMEM;
 }
 

Thanks Li!

Another thing I noticed but didn't deal with is:

static int init_rootdomain(struct root_domain *rd, bool bootmem)

{
        memset(rd, 0, sizeof(*rd));

        if (bootmem) {
                alloc_bootmem_cpumask_var(&def_root_domain.span);
                alloc_bootmem_cpumask_var(&def_root_domain.online);
                alloc_bootmem_cpumask_var(&def_root_domain.rto_mask);
                cpupri_init(&rd->cpupri, true);
                return 0;
        }
        if (!alloc_cpumask_var(&rd->span, GFP_KERNEL))
		...

Note that under the if (bootmem) case, it specifies the addresses directly instead of using (&rd->span) as the other alloc's do.

Not a big deal, just an inconsistency.

Thanks,
Mike

author
#6 lore raw
Quoted 16 lines

Another thing I noticed but didn't deal with is:

static int init_rootdomain(struct root_domain *rd, bool bootmem)

{
        memset(rd, 0, sizeof(*rd));

        if (bootmem) {
                alloc_bootmem_cpumask_var(&def_root_domain.span);
                alloc_bootmem_cpumask_var(&def_root_domain.online);
                alloc_bootmem_cpumask_var(&def_root_domain.rto_mask);
                cpupri_init(&rd->cpupri, true);
                return 0;
        }
        if (!alloc_cpumask_var(&rd->span, GFP_KERNEL))
		...
Quoted 5 lines

Note that under the if (bootmem) case, it specifies the addresses directly instead of using (&rd->span) as the other alloc's do.

Not a big deal, just an inconsistency.

I didn't notice this. :)

What makes it a bit worse is another inconsistency in if(bootmem), that rd is used in cpupri_init() but def_root_domain is used in alloc()s.