Thread (13 messages) 13 messages, 2 authors, 2025-01-09

Re: [PATCH v5 5/5] tracing: Adopt __free() and guard() for trace_fprobe.c

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Date: 2025-01-09 01:43:35
Also in: lkml

On Wed, 8 Jan 2025 10:07:36 -0500
Steven Rostedt [off-list ref] wrote:
On Wed,  8 Jan 2025 11:11:30 +0900
"Masami Hiramatsu (Google)" [off-list ref] wrote:
quoted
@@ -1234,24 +1223,26 @@ static int __trace_fprobe_create(int argc, const char *argv[])
 			trace_probe_log_err(0, BAD_PROBE_ADDR);
 		else if (ret != -ENOMEM && ret != -EEXIST)
 			trace_probe_log_err(0, FAIL_REG_PROBE);
-		goto error;
-	}
+		ret = -EINVAL;
+	} else
+		/* 'tf' is successfully registered. To avoid freeing, assign NULL. */
+		tf = NULL;
 
-out:
-	if (tp_mod)
-		module_put(tp_mod);
+	return ret;
+}
+
Hmm, the above could probably be simplified as:

	ret = register_trace_fprobe(tf);
	if (ret) {
		trace_probe_log_set_index(1);
		if (ret == -EILSEQ)
			trace_probe_log_err(0, BAD_INSN_BNDRY);
		else if (ret == -ENOENT)
			trace_probe_log_err(0, BAD_PROBE_ADDR);
		else if (ret != -ENOMEM && ret != -EEXIST)
			trace_probe_log_err(0, FAIL_REG_PROBE);
		return -EINVAL;
	}

	/* 'tf' is successfully registered. To avoid freeing, assign NULL. */
	tf = NULL;

	return 0;
Indeed. Thanks!
 }

-- Steve

-- 
Masami Hiramatsu (Google) [off-list ref]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help