Skip to contentSkip to conversation

perf probe: Fix uninitialized variable

PATCH Applied James Clark 3 participants 7 messages Dec 11, 2024 – Jan 13, 2025 perf events

lore
Share & tools
lore

James Clark

author reviewer
#0 lore raw

v2 cover perf probe: Fix uninitialized variable

Changes since V1:

* Split into a fixes commit and tidyup
* Pick up tags

James Clark (2):
perf probe: Fix uninitialized variable
perf probe: Rename err label

 tools/perf/util/probe-event.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.34.1
author reviewer
#1 lore raw

PATCH v2 1/2 perf probe: Fix uninitialized variable

Since the linked fixes: commit, err is returned uninitialized due to the removal of "return 0". Initialize err to fix it.

This fixes the following intermittent test failure on release builds:

 $ perf test "testsuite_probe"
 ...
 -- [ FAIL ] -- perf_probe :: test_invalid_options :: mutually exclusive options :: -L foo -V bar (output regexp parsing)
 Regexp not found: \"Error: switch .+ cannot be used with switch .+\"
 ...
Fixes 080e47b2a237 ("perf probe: Introduce quotation marks support")
---
 tools/perf/util/probe-event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
index 6d51a4c98ad7..eaa0318e9b87 100644
@@ -1370,7 +1370,7 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 {
 	char *buf = strdup(arg);
 	char *p;
-	int err;
+	int err = 0;
 
 	if (!buf)
 		return -ENOMEM;
Signature · 1 line
2.34.1
#2 lore raw
Quoted 10 lines · James Clark

Since the linked fixes: commit, err is returned uninitialized due to the removal of "return 0". Initialize err to fix it.

This fixes the following intermittent test failure on release builds:

 $ perf test "testsuite_probe"
 ...
 -- [ FAIL ] -- perf_probe :: test_invalid_options :: mutually exclusive options :: -L foo -V bar (output regexp parsing)
 Regexp not found: \"Error: switch .+ cannot be used with switch .+\"
 ...

So Namhyung, this one should go to perf-tools, I can pick the second on perf-tools-next, so that we keep perf-tools as small as possible.

- Arnaldo

Quoted 24 lines
Fixes 080e47b2a237 ("perf probe: Introduce quotation marks support")
---
 tools/perf/util/probe-event.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/probe-event.c +1 -1
index 6d51a4c98ad7..eaa0318e9b87 100644
@@ -1370,7 +1370,7 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 {
 	char *buf = strdup(arg);
 	char *p;
-	int err;
+	int err = 0;
 
 	if (!buf)
 		return -ENOMEM;
Signature · 1 line
2.34.1
maintainer
#3 lore raw

Hello,

Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 5 lines · James Clark

Since the linked fixes: commit, err is returned uninitialized due to the removal of "return 0". Initialize err to fix it.

This fixes the following intermittent test failure on release builds:

Quoted 8 lines
Quoted 5 lines
 $ perf test "testsuite_probe"
 ...
 -- [ FAIL ] -- perf_probe :: test_invalid_options :: mutually exclusive options :: -L foo -V bar (output regexp parsing)
 Regexp not found: \"Error: switch .+ cannot be used with switch .+\"
 ...

So Namhyung, this one should go to perf-tools, I can pick the second on perf-tools-next, so that we keep perf-tools as small as possible.

Sure, will replace and force-push.

Thanks,
Namhyung

maintainer Applied
#4 lore raw
Quoted 15 lines · Namhyung Kim

Hello,

Quoted 12 lines · Arnaldo Carvalho de Melo
Quoted 10 lines · James Clark

Since the linked fixes: commit, err is returned uninitialized due to the removal of "return 0". Initialize err to fix it.

This fixes the following intermittent test failure on release builds:

 $ perf test "testsuite_probe"
 ...
 -- [ FAIL ] -- perf_probe :: test_invalid_options :: mutually exclusive options :: -L foo -V bar (output regexp parsing)
 Regexp not found: \"Error: switch .+ cannot be used with switch .+\"
 ...
Quoted 4 lines
Quoted 2 lines

So Namhyung, this one should go to perf-tools, I can pick the second on perf-tools-next, so that we keep perf-tools as small as possible.

Sure, will replace and force-push.

Applied patch 1 to perf-tools, thanks!

Best regards,
Namhyung

author reviewer
#5 lore raw

PATCH v2 2/2 perf probe: Rename err label

In reply to James Clark

Rename err to out to avoid confusion because buf is still supposed to be freed in non error cases.

---
 tools/perf/util/probe-event.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
tools/perf/util/probe-event.c +9 -9
index eaa0318e9b87..35af6570cf9b 100644
@@ -1383,20 +1383,20 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 		if (p == buf) {
 			semantic_error("No file/function name in '%s'.\n", p);
 			err = -EINVAL;
-			goto err;
+			goto out;
 		}
 		*(p++) = '\0';
 
 		err = parse_line_num(&p, &lr->start, "start line");
 		if (err)
-			goto err;
+			goto out;
 
 		if (*p == '+' || *p == '-') {
 			const char c = *(p++);
 
 			err = parse_line_num(&p, &lr->end, "end line");
 			if (err)
-				goto err;
+				goto out;
 
 			if (c == '+') {
 				lr->end += lr->start;
@@ -1416,11 +1416,11 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 		if (lr->start > lr->end) {
 			semantic_error("Start line must be smaller"
 				       " than end line.\n");
-			goto err;
+			goto out;
 		}
 		if (*p != '\0') {
 			semantic_error("Tailing with invalid str '%s'.\n", p);
-			goto err;
+			goto out;
 		}
 	}
 
@@ -1431,7 +1431,7 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 			lr->file = strdup_esq(p);
 			if (lr->file == NULL) {
 				err = -ENOMEM;
-				goto err;
+				goto out;
 			}
 		}
 		if (*buf != '\0')
@@ -1439,7 +1439,7 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 		if (!lr->function && !lr->file) {
 			semantic_error("Only '@*' is not allowed.\n");
 			err = -EINVAL;
-			goto err;
+			goto out;
 		}
 	} else if (strpbrk_esq(buf, "/."))
 		lr->file = strdup_esq(buf);
@@ -1448,10 +1448,10 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 	else {	/* Invalid name */
 		semantic_error("'%s' is not a valid function name.\n", buf);
 		err = -EINVAL;
-		goto err;
+		goto out;
 	}
 
-err:
+out:
 	free(buf);
 	return err;
 }
Signature · 1 line
2.34.1
maintainer Applied
#6 lore raw

Re: [PATCH v2 2/2] perf probe: Rename err label

Quoted 2 lines · James Clark

Rename err to out to avoid confusion because buf is still supposed to be freed in non error cases.

Thanks, applied to perf-tools-next,

- Arnaldo

Quoted 84 lines
---
 tools/perf/util/probe-event.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
tools/perf/util/probe-event.c +9 -9
index eaa0318e9b87..35af6570cf9b 100644
@@ -1383,20 +1383,20 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 		if (p == buf) {
 			semantic_error("No file/function name in '%s'.\n", p);
 			err = -EINVAL;
-			goto err;
+			goto out;
 		}
 		*(p++) = '\0';
 
 		err = parse_line_num(&p, &lr->start, "start line");
 		if (err)
-			goto err;
+			goto out;
 
 		if (*p == '+' || *p == '-') {
 			const char c = *(p++);
 
 			err = parse_line_num(&p, &lr->end, "end line");
 			if (err)
-				goto err;
+				goto out;
 
 			if (c == '+') {
 				lr->end += lr->start;
@@ -1416,11 +1416,11 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 		if (lr->start > lr->end) {
 			semantic_error("Start line must be smaller"
 				       " than end line.\n");
-			goto err;
+			goto out;
 		}
 		if (*p != '\0') {
 			semantic_error("Tailing with invalid str '%s'.\n", p);
-			goto err;
+			goto out;
 		}
 	}
 
@@ -1431,7 +1431,7 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 			lr->file = strdup_esq(p);
 			if (lr->file == NULL) {
 				err = -ENOMEM;
-				goto err;
+				goto out;
 			}
 		}
 		if (*buf != '\0')
@@ -1439,7 +1439,7 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 		if (!lr->function && !lr->file) {
 			semantic_error("Only '@*' is not allowed.\n");
 			err = -EINVAL;
-			goto err;
+			goto out;
 		}
 	} else if (strpbrk_esq(buf, "/."))
 		lr->file = strdup_esq(buf);
@@ -1448,10 +1448,10 @@ int parse_line_range_desc(const char *arg, struct line_range *lr)
 	else {	/* Invalid name */
 		semantic_error("'%s' is not a valid function name.\n", buf);
 		err = -EINVAL;
-		goto err;
+		goto out;
 	}
 
-err:
+out:
 	free(buf);
 	return err;
 }
Signature · 1 line
2.34.1