Skip to contentSkip to conversation

tools-perf: Change -1 by false

PATCH Applied Peter Senna Tschudin 3 participants 3 messages Sep 17, 2015 – Sep 18, 2015 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools-perf: Change -1 by false

Returning a negative value for a boolean function seem to have the undesired effect of returning true. Replace -1 by false in a bool-returning function.

The diff of the .s file before and after the change (for x86_64):
3907c3907
< movl $1, %ebx
---

Quoted 1 line
	xorl	%ebx, %ebx

while if -1 is replaced by true, the diff is empty.

This issue was found by the following Coccinelle semantic patch:
<smpl>
@@
identifier f;
constant C;
typedef bool;
@@
bool f (...){
<+...
* return -C;
...+>
}
</smpl>

---
 tools/perf/util/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/util.c +1 -1
index 49a5c6a..ce465b2 100644
@@ -639,7 +639,7 @@ bool find_process(const char *name)
 
 	dir = opendir(procfs__mountpoint());
 	if (!dir)
-		return -1;
+		return false;
 
 	/* Walk through the directory. */
 	while (ret && (d = readdir(dir)) != NULL) {
Signature · 1 line
2.1.0
maintainer Applied
#1 lore raw

Em Thu, Sep 17, 2015 at 12:08:53PM +0200, Peter Senna Tschudin escreveu:

Quoted 8 lines

Returning a negative value for a boolean function seem to have the undesired effect of returning true. Replace -1 by false in a bool-returning function.

The diff of the .s file before and after the change (for x86_64):
3907c3907
< movl $1, %ebx
---

Please avoid adding a --- at the start of any changeset comment line, it breaks scripts.

Thanks, applied.

- Arnaldo

Quoted 38 lines
Quoted 1 line
	xorl	%ebx, %ebx

while if -1 is replaced by true, the diff is empty.

This issue was found by the following Coccinelle semantic patch:
<smpl>
@@
identifier f;
constant C;
typedef bool;
@@
bool f (...){
<+...
* return -C;
...+>
}
</smpl>

---
 tools/perf/util/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/util.c +1 -1
index 49a5c6a..ce465b2 100644
@@ -639,7 +639,7 @@ bool find_process(const char *name)
 
 	dir = opendir(procfs__mountpoint());
 	if (!dir)
-		return -1;
+		return false;
 
 	/* Walk through the directory. */
 	while (ret && (d = readdir(dir)) != NULL) {
Signature · 1 line
2.1.0
#2 lore raw

[tip:perf/urgent] perf tools: Bool functions shouldn't return -1

In reply to Peter Senna Tschudin
perf tools: Bool functions shouldn't return -1
Commit-ID:  bf6445631c6f00882b25516a174d5073ce0c6f81
Gitweb:     http://git.kernel.org/tip/bf6445631c6f00882b25516a174d5073ce0c6f81
Author:     Peter Senna Tschudin <[email protected]>
AuthorDate: Thu, 17 Sep 2015 12:08:53 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 17 Sep 2015 15:31:52 -0300

perf tools: Bool functions shouldn't return -1

Returning a negative value for a boolean function seem to have the undesired effect of returning true. Replace -1 by false in a bool-returning function.

The diff of the .s file before and after the change (for x86_64):

3907c3907
< movl $1, %ebx
---

Quoted 1 line
	xorl	%ebx, %ebx

while if -1 is replaced by true, the diff is empty.

This issue was found by the following Coccinelle semantic patch:

  <smpl>
  @@
  identifier f;
  constant C;
  typedef bool;
  @@
  bool f (...){
  <+...
  * return -C;
  ...+>
  }
  </smpl>
---
 tools/perf/util/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/util.c +1 -1
index 7acafb3..c2cd9bf2 100644
@@ -709,7 +709,7 @@ bool find_process(const char *name)
 
 	dir = opendir(procfs__mountpoint());
 	if (!dir)
-		return -1;
+		return false;
 
 	/* Walk through the directory. */
 	while (ret && (d = readdir(dir)) != NULL) {