Skip to contentSkip to conversation

perf: Fix a precedence bug

PATCH In review He Kuang 3 participants 7 messages Feb 27, 2015 – Feb 28, 2015 perf events

lore
Share & tools
lore

He Kuang

author
#0 lore raw

PATCH 1/1 perf: Fix a precedence bug

The minus operator has higher precedence than ?:
Add parentheses around ?: fix this.

---
 tools/perf/util/probe-event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
index 919937e..bed8d0f 100644
@@ -150,7 +150,7 @@ static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc)
 		sym = __find_kernel_function_by_name(name, &map);
 		if (sym)
 			return map->unmap_ip(map, sym->start) -
-				(reloc) ? 0 : map->reloc;
+				((reloc) ? 0 : map->reloc);
 	}
 	return 0;
 }
Signature · 1 line
2.2.0.33.gc18b867
author
#1 lore raw
Quoted 19 lines · He Kuang

The minus operator has higher precedence than ?:
Add parentheses around ?: fix this.

---
  tools/perf/util/probe-event.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
index 919937e..bed8d0f 100644
@@ -150,7 +150,7 @@ static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc)
  		sym = __find_kernel_function_by_name(name, &map);
  		if (sym)
  			return map->unmap_ip(map, sym->start) -
-				(reloc) ? 0 : map->reloc;
+				((reloc) ? 0 : map->reloc);
  	}
  	return 0;
  }
#2 lore raw
In reply to He Kuang

Hi,

Quoted 2 lines · He Kuang

The minus operator has higher precedence than ?:
Add parentheses around ?: fix this.

Thank you for fixing that,

Could you give us an actual example of the result? e.g. What happened? and how to reproduce it?

Thank you,

Quoted 18 lines
---
 tools/perf/util/probe-event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
index 919937e..bed8d0f 100644
@@ -150,7 +150,7 @@ static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc)
 		sym = __find_kernel_function_by_name(name, &map);
 		if (sym)
 			return map->unmap_ip(map, sym->start) -
-				(reloc) ? 0 : map->reloc;
+				((reloc) ? 0 : map->reloc);
 	}
 	return 0;
 }
Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
author
#3 lore raw

PATCH 1/1 perf: Fix a precedence bug

The minus operator has higher precedence than ?:
Add parentheses around ?: fix this.

Before this patch:

$ echo 'p:myprobe do_sys_open' > /sys/kernel/debug/tracing/kprobe_events
$ perf probe -l -k ../vmlinux
  kprobes:myprobe      (on do_sys_open)

After this patch:

$ echo 'p:myprobe do_sys_open' > /sys/kernel/debug/tracing/kprobe_events
$ perf probe -l -k ../vmlinux
  kprobes:myprobe      (on [email protected]/fs/open.c)
---
 tools/perf/util/probe-event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
index 919937e..bed8d0f 100644
@@ -150,7 +150,7 @@ static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc)
 		sym = __find_kernel_function_by_name(name, &map);
 		if (sym)
 			return map->unmap_ip(map, sym->start) -
-				(reloc) ? 0 : map->reloc;
+				((reloc) ? 0 : map->reloc);
 	}
 	return 0;
 }
Signature · 1 line
2.2.0.33.gc18b867
Acked-by on v1 1/1
#4 lore raw
Quoted 4 lines · He Kuang

The minus operator has higher precedence than ?:
Add parentheses around ?: fix this.

Before this patch:

Quoted 8 lines
$ echo 'p:myprobe do_sys_open' > /sys/kernel/debug/tracing/kprobe_events
$ perf probe -l -k ../vmlinux
  kprobes:myprobe      (on do_sys_open)

After this patch:

$ echo 'p:myprobe do_sys_open' > /sys/kernel/debug/tracing/kprobe_events
$ perf probe -l -k ../vmlinux
  kprobes:myprobe      (on [email protected]/fs/open.c)

Thanks for finding this bug!

Quoted 20 lines
---
 tools/perf/util/probe-event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
index 919937e..bed8d0f 100644
@@ -150,7 +150,7 @@ static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc)
 		sym = __find_kernel_function_by_name(name, &map);
 		if (sym)
 			return map->unmap_ip(map, sym->start) -
-				(reloc) ? 0 : map->reloc;
+				((reloc) ? 0 : map->reloc);
 	}
 	return 0;
 }
Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#5 lore raw
In reply to He Kuang
Quoted 4 lines · He Kuang

The minus operator has higher precedence than ?:
Add parentheses around ?: fix this.

Before this patch:

Quoted 8 lines
$ echo 'p:myprobe do_sys_open' > /sys/kernel/debug/tracing/kprobe_events
$ perf probe -l -k ../vmlinux
  kprobes:myprobe      (on do_sys_open)

After this patch:

$ echo 'p:myprobe do_sys_open' > /sys/kernel/debug/tracing/kprobe_events
$ perf probe -l -k ../vmlinux
  kprobes:myprobe      (on [email protected]/fs/open.c)

BTW, on my environment (CentOS7)

# ./perf probe -a do_fork
Added new event:
  probe:do_fork        (on do_fork)

You can now use it in all perf tools, such as:

perf record -e probe:do_fork -aR sleep 1

# ./perf probe -l
  probe:do_fork        (on do_fork@kernel/fork.c)
# ./perf probe -l -k /usr/lib/debug/lib/modules/3.10.0-123.13.2.el7.x86_64/vmlinux
  probe:do_fork        (on do_fork@kernel/fork.c)

Hm, the current perf (without this patch) seems work... But anyway, it looks safer to brace it.

Thank you,

Quoted 20 lines
---
 tools/perf/util/probe-event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
index 919937e..bed8d0f 100644
@@ -150,7 +150,7 @@ static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc)
 		sym = __find_kernel_function_by_name(name, &map);
 		if (sym)
 			return map->unmap_ip(map, sym->start) -
-				(reloc) ? 0 : map->reloc;
+				((reloc) ? 0 : map->reloc);
 	}
 	return 0;
 }
Signature · 4 lines
Masami HIRAMATSU
Software Platform Research Dept. Linux Technology Research Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: [email protected]
#6 lore raw

[tip:perf/core] perf probe: Fix a precedence bug

In reply to He Kuang
perf probe: Fix a precedence bug
Commit-ID:  f56847c2e99810781f6941d01baff9ae223eeac3
Gitweb:     http://git.kernel.org/tip/f56847c2e99810781f6941d01baff9ae223eeac3
Author:     He Kuang <[email protected]>
AuthorDate: Fri, 27 Feb 2015 18:52:53 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 27 Feb 2015 10:31:09 -0300

perf probe: Fix a precedence bug

The minus operator has higher precedence than ?: Add parentheses around ?: fix this.

Before this patch:

  $ echo 'p:myprobe do_sys_open' > /sys/kernel/debug/tracing/kprobe_events
  $ perf probe -l -k ../vmlinux
    kprobes:myprobe      (on do_sys_open)

After this patch:

  $ echo 'p:myprobe do_sys_open' > /sys/kernel/debug/tracing/kprobe_events
  $ perf probe -l -k ../vmlinux
    kprobes:myprobe      (on [email protected]/fs/open.c)
---
 tools/perf/util/probe-event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
index 9526cf3..7c0e765 100644
@@ -151,7 +151,7 @@ static u64 kernel_get_symbol_address_by_name(const char *name, bool reloc)
 		sym = __find_kernel_function_by_name(name, &map);
 		if (sym)
 			return map->unmap_ip(map, sym->start) -
-				(reloc) ? 0 : map->reloc;
+				((reloc) ? 0 : map->reloc);
 	}
 	return 0;
 }