Skip to contentSkip to conversation

sparc: vDSO: Silence an uninitialized variable warning

PATCH Applied Dan Carpenter 3 participants 5 messages Oct 13, 2018 – Oct 18, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparc: vDSO: Silence an uninitialized variable warning

Smatch complains that "val" would be uninitialized if kstrtoul() fails.

Fixes 9a08862a5d2e ("vDSO for sparc")
---
 arch/sparc/vdso/vma.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/sparc/vdso/vma.c +3 -1
index f51595f861b8..5eaff3c1aa0c 100644
@@ -262,7 +262,9 @@ static __init int vdso_setup(char *s)
 	unsigned long val;
 
 	err = kstrtoul(s, 10, &val);
+	if (err)
+		return err;
 	vdso_enabled = val;
-	return err;
+	return 0;
 }
 __setup("vdso=", vdso_setup);
Signature · 1 line
2.18.0
#1 lore raw
Quoted 14 lines · Dan Carpenter

Smatch complains that "val" would be uninitialized if kstrtoul() fails.

Fixes 9a08862a5d2e ("vDSO for sparc")
---
  arch/sparc/vdso/vma.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/sparc/vdso/vma.c +0 -0
index f51595f861b8..5eaff3c1aa0c 100644

arch/sparc/vdso/vma.c static __init int vdso_setup(char *s) · line 270

Quoted 10 lines
arch/sparc/vdso/vma.c +3 -1
@@ -262,7 +262,9 @@ static __init int vdso_setup(char *s)
  	unsigned long val;
 
  	err = kstrtoul(s, 10, &val);
+	if (err)
+		return err;
  	vdso_enabled = val;
-	return err;
+	return 0;
  }
  __setup("vdso=", vdso_setup);

This is probably fine, but it might be cleaner as

    	err = kstrtoul(s, 10, &val);
	if (!err)
		vdso_enabled = val;
	return err;

sln

#2 lore raw
In reply to Dan Carpenter
Quoted 27 lines · Shannon Nelson
Quoted 13 lines · Dan Carpenter

Smatch complains that "val" would be uninitialized if kstrtoul() fails.

Fixes 9a08862a5d2e ("vDSO for sparc")
---
  arch/sparc/vdso/vma.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/sparc/vdso/vma.c +0 -0
index f51595f861b8..5eaff3c1aa0c 100644

arch/sparc/vdso/vma.c static __init int vdso_setup(char *s) · line 270

Quoted 10 lines
arch/sparc/vdso/vma.c +3 -1
@@ -262,7 +262,9 @@ static __init int vdso_setup(char *s)
  	unsigned long val;
  	err = kstrtoul(s, 10, &val);
+	if (err)
+		return err;
  	vdso_enabled = val;
-	return err;
+	return 0;
  }
  __setup("vdso=", vdso_setup);
 

This is probably fine, but it might be cleaner as

Quoted 4 lines
   	err = kstrtoul(s, 10, &val);
	if (!err)
		vdso_enabled = val;
	return err;

I always tell people to do failure handling instead of success handling. And also I tell people not to make the last if statement in a function a special case. Like you see this a lot right:

	ret = frob();
	if (ret)
		return ret;

	ret = frob();
	if (ret)
		return ret;

	ret = frob();
	if (!ret)
		*p = whatever;
	return ret;

If you do failure handling then the success path is at indent level one and failure handling is two tabs. But if you mix it up it's not as clear. I have never studied this, but my impression from looking at static analysis over the years is that success handling is error prone.

regards,
dan carpenter

#3 lore raw
In reply to Dan Carpenter
Quoted 50 lines · Dan Carpenter
Quoted 27 lines · Shannon Nelson
Quoted 13 lines · Dan Carpenter

Smatch complains that "val" would be uninitialized if kstrtoul() fails.

Fixes 9a08862a5d2e ("vDSO for sparc")
---
   arch/sparc/vdso/vma.c | 4 +++-
   1 file changed, 3 insertions(+), 1 deletion(-)
arch/sparc/vdso/vma.c +0 -0
index f51595f861b8..5eaff3c1aa0c 100644

arch/sparc/vdso/vma.c static __init int vdso_setup(char *s) · line 270

Quoted 10 lines
arch/sparc/vdso/vma.c +3 -1
@@ -262,7 +262,9 @@ static __init int vdso_setup(char *s)
   	unsigned long val;
   	err = kstrtoul(s, 10, &val);
+	if (err)
+		return err;
   	vdso_enabled = val;
-	return err;
+	return 0;
   }
   __setup("vdso=", vdso_setup);
 

This is probably fine, but it might be cleaner as

Quoted 4 lines
    	err = kstrtoul(s, 10, &val);
	if (!err)
		vdso_enabled = val;
	return err;

I always tell people to do failure handling instead of success handling. And also I tell people not to make the last if statement in a function a special case. Like you see this a lot right:

	ret = frob();
	if (ret)
		return ret;

	ret = frob();
	if (ret)
		return ret;

	ret = frob();
	if (!ret)
		*p = whatever;
	return ret;
Quoted 8 lines

If you do failure handling then the success path is at indent level one and failure handling is two tabs. But if you mix it up it's not as clear. I have never studied this, but my impression from looking at static analysis over the years is that success handling is error prone.

regards,
dan carpenter

(driving right into the bikeshed...)

Yes, and that's the way I would normally go, especially if there was more to that little function. But in this case with such a short little function, I hate seeing it messed up with unnecessary lines.

Anyway, enough with the noise, either way is fine.

sln