Skip to contentSkip to conversation

perf tools: Fix regcomp() error detection in SDT probes

PATCH New Kaushlendra Kumar 1 participant 1 message Sep 2, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf tools: Fix regcomp() error detection in SDT probes

The regcomp() function returns 0 on success and a non-zero error code on failure, not negative values. The current code incorrectly checks for ret < 0, which would miss positive error codes returned by regcomp().

Fix the error checking in sdt_init_op_regex() and arch_sdt_arg_parse_op() to properly check for non-zero return values using ret != 0, ensuring all regcomp() failures are correctly detected and handled.

---
 tools/perf/arch/x86/util/perf_regs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/arch/x86/util/perf_regs.c +2 -2
index 12fd93f04802..1e9967a98889 100644
@@ -156,7 +156,7 @@ static int sdt_init_op_regex(void)
 		return 0;
 
 	ret = regcomp(&sdt_op_regex, SDT_OP_REGEX, REG_EXTENDED);
-	if (ret < 0) {
+	if (ret != 0) {
 		pr_debug4("Regex compilation error.\n");
 		return ret;
 	}
@@ -215,7 +215,7 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)
 	char prefix[3] = {0};
 
 	ret = sdt_init_op_regex();
-	if (ret < 0)
+	if (ret != 0)
 		return ret;
 
 	/*
Signature · 1 line
2.34.1