Skip to contentSkip to conversation

sched: add sanity check in partition_sched_domains()

PATCH Applied Li Zefan 2 participants 3 messages Nov 4, 2008

lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 sched: add sanity check in partition_sched_domains()

It's wrong to make dattr_new = NULL if doms_new == NULL, it introduces memory leak if dattr_new != NULL. Fortunately dattr_new is always NULL in this case. So remove the code and add a sanity check.

---
 kernel/sched.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sched.c +1 -1
index baa7e4b..0dcda75 100644
@@ -7787,7 +7787,7 @@ match1:
 		ndoms_cur = 0;
 		doms_new = &fallback_doms;
 		cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map);
-		dattr_new = NULL;
+		BUG_ON(dattr_new);
 	}
 
 	/* Build new domains */
Signature · 1 line
1.5.4.rc3
Applied
#1 lore raw
Quoted 8 lines · Li Zefan

It's wrong to make dattr_new = NULL if doms_new == NULL, it introduces memory leak if dattr_new != NULL. Fortunately dattr_new is always NULL in this case. So remove the code and add a sanity check.

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

applied to tip/sched/core, thanks!

a small detail, i changed this:

kernel/sched.c match1: · line 7790

Quoted 1 line
kernel/sched.c +1 -0
+		BUG_ON(dattr_new);

to WARN_ON_ONCE().

If there's a rare setup-time memory leak we dont want to crash the box via a BUG_ON(), as that only results in unhappy users. We want a WARN_ON_ONCE() so that we get nice bugreports and kerneloops.org coverage as well instead.

We use BUG_ON() in new code only in the rarest of circumstances: if we absolutely want to bring down the box right there - because there's a serious risk of data corruption, security breach, etc.

Ingo

author
#2 lore raw
Quoted 6 lines

a small detail, i changed this:

kernel/sched.c match1: · line 7790

Quoted 1 line
kernel/sched.c +1 -0
+		BUG_ON(dattr_new);

to WARN_ON_ONCE().

Quoted 9 lines

If there's a rare setup-time memory leak we dont want to crash the box via a BUG_ON(), as that only results in unhappy users. We want a WARN_ON_ONCE() so that we get nice bugreports and kerneloops.org coverage as well instead.

We use BUG_ON() in new code only in the rarest of circumstances: if we absolutely want to bring down the box right there - because there's a serious risk of data corruption, security breach, etc.

I see the point, thx for the explanation. :)