linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Subject: [PATCH] libtracefs: Do not allow tracefs_synth_set_instance() on created synth
Date: Tue, 30 May 2023 01:47:11 -0400	[thread overview]
Message-ID: <20230530014711.6c8b3b16@rorschach.local.home> (raw)

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If tracefs_synth_create() is called on a synthetic event descriptor, do
not let its instance change after that. Currently
tracefs_synth_set_instance() returns success when called on a created
instance, where it has no effect. Make it fail in such cases.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/tracefs-hist.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index 1e3df6c67d7e..ecfce7442176 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -748,6 +748,7 @@ struct name_hash {
  * @start_parens: Current parenthesis level for start event
  * @end_parens: Current parenthesis level for end event
  * @new_format: onmatch().trace(synth_event,..) or onmatch().synth_event(...)
+ * @created: Set if tracefs_synth_create() was called on this; cleared on destroy()
  */
 struct tracefs_synth {
 	struct tracefs_instance *instance;
@@ -778,6 +779,7 @@ struct tracefs_synth {
 	char			arg_name[16];
 	int			arg_cnt;
 	bool			new_format;
+	bool			created;
 };
 
  /*
@@ -2207,7 +2209,7 @@ tracefs_synth_get_start_hist(struct tracefs_synth *synth)
  */
 int tracefs_synth_set_instance(struct tracefs_synth *synth, struct tracefs_instance *instance)
 {
-	if (!synth)
+	if (!synth || synth->created)
 		return -1;
 	synth->instance = instance;
 	return 0;
@@ -2271,6 +2273,8 @@ int tracefs_synth_create(struct tracefs_synth *synth)
 	if (ret < 0)
 		goto remove_start_hist;
 
+	synth->created = true;
+
 	return 0;
 
  remove_start_hist:
@@ -2334,6 +2338,9 @@ int tracefs_synth_destroy(struct tracefs_synth *synth)
 
 	ret = tracefs_dynevent_destroy(synth->dyn_event, true);
 
+	if (!ret)
+		synth->created = false;
+
 	return ret ? -1 : 0;
 }
 
-- 
2.39.2


                 reply	other threads:[~2023-05-30  5:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230530014711.6c8b3b16@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).