Skip to contentSkip to conversation

sched/core: silence a warning in sched_init()

PATCH Superseded Qian Cai 1 participant 1 message Jul 19, 2019 Scheduler

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Qian Cai

author
#0 lore raw

PATCH v3 1/1 sched/core: silence a warning in sched_init()

Compiling a kernel with both FAIR_GROUP_SCHED=n and RT_GROUP_SCHED=n will generate a compiler warning,

kernel/sched/core.c: In function 'sched_init':
kernel/sched/core.c:5906:32: warning: variable 'ptr' set but not used [-Wunused-but-set-variable]

  unsigned long alloc_size = 0, ptr;
                                ^~~

Silence it by adding a check in a if statement to actually use it.

---

v3: Use a different approach to see if Peter will like it.
v2: Incorporate the feedback from Valentin.

 kernel/sched/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
kernel/sched/core.c +4 -2
index 2b037f195473..ae36a1e5b2e4 100644
@@ -6371,7 +6371,8 @@ int in_sched_functions(unsigned long addr)
 
 void __init sched_init(void)
 {
-	unsigned long alloc_size = 0, ptr;
+	unsigned long alloc_size = 0;
+	unsigned long ptr = 0;
 	int i;
 
 	wait_bit_init();
@@ -6382,7 +6383,8 @@ void __init sched_init(void)
 #ifdef CONFIG_RT_GROUP_SCHED
 	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
 #endif
-	if (alloc_size) {
+	/* Avoid a -Wunused-but-set-variable warning. */
+	if (alloc_size && !ptr) {
 		ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
Signature · 1 line
1.8.3.1