Skip to contentSkip to conversation

cpuset: sparse warnings in cpuset.c

PATCH In review Harvey Harrison 3 participants 6 messages Feb 3, 2008 – Feb 23, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpuset: sparse warnings in cpuset.c

No need to redeclare p, we have finished with it at this point, so reuse it in the for loop.

kernel/cpuset.c:824:23: warning: symbol 'p' shadows an earlier one kernel/cpuset.c:746:21: originally declared here kernel/cpuset.c:1272:52: warning: Using plain integer as NULL pointer

---
 kernel/cpuset.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
kernel/cpuset.c +3 -2
index cfaf641..fdbac43 100644
@@ -821,7 +821,7 @@ static int update_cpumask(struct cpuset *cs, char *buf)
 	cgroup_iter_end(cgrp, &it);
 	if (heap.size) {
 		for (i = 0; i < heap.size; i++) {
-			struct task_struct *p = heap.ptrs[i];
+			p = heap.ptrs[i];
 			if (i == 0) {
 				latest_time = p->start_time;
 				latest_task = p;
@@ -1269,7 +1269,8 @@ static ssize_t cpuset_common_file_write(struct cgroup *cont,
 		return -E2BIG;
 
 	/* +1 for nul-terminator */
-	if ((buffer = kmalloc(nbytes + 1, GFP_KERNEL)) == 0)
+	buffer = kmalloc(nbytes + 1, GFP_KERNEL);
+	if (!buffer)
 		return -ENOMEM;
 
 	if (copy_from_user(buffer, userbuf, nbytes)) {
Signature · 1 line
1.5.4.rc5.1138.g2602
#1 lore raw
Quoted 2 lines · Harvey

No need to redeclare p, we have finished with it at this point, so reuse it in the for loop.

Good catch, however I disagree with the fix. It makes the code more brittle.

It's not a good idea to reuse a variable for some other purpose just because you "know" the original use is dead. Things don't necessarily stay dead; code moves around.

Could you prepare a revised version of this patch, that instead of dropping that declaration of 'p', rather renames it to 'q' ?

Thanks.

Signature · 3 lines
                  I won't rest till it's the best ...
                  Programmer, Linux Scalability
                  Paul Jackson <[email protected]> 1.940.382.4214
#2 lore raw

Don't redeclare p, use a new variable q.

kernel/cpuset.c:824:23: warning: symbol 'p' shadows an earlier one kernel/cpuset.c:746:21: originally declared here kernel/cpuset.c:1272:52: warning: Using plain integer as NULL pointer

---
Paul, used a variable q instead as per your request.

 kernel/cpuset.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
kernel/cpuset.c +7 -6
index cfaf641..ce0cfff 100644
@@ -821,13 +821,13 @@ static int update_cpumask(struct cpuset *cs, char *buf)
 	cgroup_iter_end(cgrp, &it);
 	if (heap.size) {
 		for (i = 0; i < heap.size; i++) {
-			struct task_struct *p = heap.ptrs[i];
+			struct task_struct *q = heap.ptrs[i];
 			if (i == 0) {
-				latest_time = p->start_time;
-				latest_task = p;
+				latest_time = q->start_time;
+				latest_task = q;
 			}
-			set_cpus_allowed(p, cs->cpus_allowed);
-			put_task_struct(p);
+			set_cpus_allowed(q, cs->cpus_allowed);
+			put_task_struct(q);
 		}
 		/*
 		 * If we had to process any tasks at all, scan again
@@ -1269,7 +1269,8 @@ static ssize_t cpuset_common_file_write(struct cgroup *cont,
 		return -E2BIG;
 
 	/* +1 for nul-terminator */
-	if ((buffer = kmalloc(nbytes + 1, GFP_KERNEL)) == 0)
+	buffer = kmalloc(nbytes + 1, GFP_KERNEL);
+	if (!buffer)
 		return -ENOMEM;
 
 	if (copy_from_user(buffer, userbuf, nbytes)) {
Signature · 1 line
1.5.4.rc5.1138.g2602
#4 lore raw
In reply to Harvey Harrison

On Sat, 02 Feb 2008 23:42:23 -0800 Harvey Harrison <[email protected]> wrote:

        ^^^^^^ I suck.
Quoted 26 lines

Don't redeclare p, use a new variable q.

kernel/cpuset.c:824:23: warning: symbol 'p' shadows an earlier one kernel/cpuset.c:746:21: originally declared here kernel/cpuset.c:1272:52: warning: Using plain integer as NULL pointer

---
Paul, used a variable q instead as per your request.

 kernel/cpuset.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
kernel/cpuset.c +1 -3
index cfaf641..ce0cfff 100644
@@ -821,13 +821,13 @@ static int update_cpumask(struct cpuset *cs, char *buf)
 	cgroup_iter_end(cgrp, &it);
 	if (heap.size) {
 		for (i = 0; i < heap.size; i++) {
-			struct task_struct *p = heap.ptrs[i];
+			struct task_struct *q = heap.ptrs[i];
 			if (i == 0) {
-				latest_time = p->start_time;
-				latest_task = p;

kernel/cpuset.c static int update_cpumask(struct cpuset *cs, char *buf) · line 833

Quoted 10 lines
kernel/cpuset.c +4 -2
+				latest_time = q->start_time;
+				latest_task = q;
 			}
-			set_cpus_allowed(p, cs->cpus_allowed);
-			put_task_struct(p);
+			set_cpus_allowed(q, cs->cpus_allowed);
+			put_task_struct(q);
 		}
 		/*
 		 * If we had to process any tasks at all, scan again

Sorry, the above code doesn't seem to exist any more.

#5 lore raw
Quoted 1 line · akpm

^^^^^^ I suck.

Yeah, right ... and Dolly Parton is flat chested ;).

Quoted 1 line

Sorry, the above code doesn't seem to exist any more.

It moved from cpuset.c to cgroup.c. I just sent a reincarnated patch:

[PATCH] cgroup: fix sparse warning of shadow symbol in cgroup.c

Signature · 3 lines
                  I won't rest till it's the best ...
                  Programmer, Linux Scalability
                  Paul Jackson <[email protected]> 1.940.382.4214