Skip to contentSkip to conversation

sched/core: silence a warning in sched_init()

PATCH New Qian Cai 2 participants 2 messages Jul 20, 2019 – Jul 25, 2019 Scheduler

lore
Share & tools
lore

Qian Cai

author
#0 lore raw

PATCH v4 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;
                               ^~~

It is unnecessary to have both "alloc_size" and "ptr", so just combine them.

---

v4: Combine "alloc_size" and "ptr" together.
v3: Use a different approach to see if Peter will like it.
v2: Incorporate the feedback from Valentin.

 kernel/sched/core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/sched/core.c +5 -5
index 2b037f195473..6eefaeea4c88 100644
@@ -6371,19 +6371,19 @@ DECLARE_PER_CPU(cpumask_var_t, select_idle_mask);
 
 void __init sched_init(void)
 {
-	unsigned long alloc_size = 0, ptr;
+	unsigned long ptr = 0;
 	int i;
 
 	wait_bit_init();
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
+	ptr += 2 * nr_cpu_ids * sizeof(void **);
 #endif
 #ifdef CONFIG_RT_GROUP_SCHED
-	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
+	ptr += 2 * nr_cpu_ids * sizeof(void **);
 #endif
-	if (alloc_size) {
-		ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
+	if (ptr) {
+		ptr = (unsigned long)kzalloc(ptr, GFP_NOWAIT);
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
 		root_task_group.se = (struct sched_entity **)ptr;
Signature · 1 line
2.20.1 (Apple Git-117)
#1 lore raw

[tip:sched/core] sched/core: Silence a warning in sched_init()

sched/core: Silence a warning in sched_init()
Commit-ID:  a1dc0446d64966dc0ae756aebdc449f335742c13
Gitweb:     https://git.kernel.org/tip/a1dc0446d64966dc0ae756aebdc449f335742c13
Author:     Qian Cai <[email protected]>
AuthorDate: Fri, 19 Jul 2019 21:23:19 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 25 Jul 2019 15:55:05 +0200

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

It is unnecessary to have both "alloc_size" and "ptr", so just combine them.

---
 kernel/sched/core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
kernel/sched/core.c +5 -5
index 042c736b2b73..46f3ca9e392a 100644
@@ -6430,19 +6430,19 @@ DECLARE_PER_CPU(cpumask_var_t, select_idle_mask);
 
 void __init sched_init(void)
 {
-	unsigned long alloc_size = 0, ptr;
+	unsigned long ptr = 0;
 	int i;
 
 	wait_bit_init();
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
-	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
+	ptr += 2 * nr_cpu_ids * sizeof(void **);
 #endif
 #ifdef CONFIG_RT_GROUP_SCHED
-	alloc_size += 2 * nr_cpu_ids * sizeof(void **);
+	ptr += 2 * nr_cpu_ids * sizeof(void **);
 #endif
-	if (alloc_size) {
-		ptr = (unsigned long)kzalloc(alloc_size, GFP_NOWAIT);
+	if (ptr) {
+		ptr = (unsigned long)kzalloc(ptr, GFP_NOWAIT);
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
 		root_task_group.se = (struct sched_entity **)ptr;