All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libtracefs: Do not discard const ename for updating it
@ 2026-11-08  8:48 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2026-11-08  8:48 UTC (permalink / raw)
  To: Linux Trace Devel

From: Steven Rostedt <rostedt@goodmis.org>

The const char *ename is set as the event name that is passed into
kprobe_alloc(). If the event isn't defined, then it uses the address
instead. It creates a copy of the addr and zeros out a ':' if it exists.
Currently, this is done by pointing ename at the newly allocated addr copy
and it is modified by a temp variable. But the compiler complains that the
temp variable discards the const (which it does).

Instead of playing games with the const ename, use a new char *aname
variable to copy the addr with and do the updates. Then set ename to point
to this variable when the event name doesn't exist.

By initializing aname to NULL it can always be freed without having to
test if event is defined or not. This removes having to typecast ename to
free it too.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 src/tracefs-kprobes.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/tracefs-kprobes.c b/src/tracefs-kprobes.c
index 09b09d7ace04..2297d078b330 100644
--- a/src/tracefs-kprobes.c
+++ b/src/tracefs-kprobes.c
@@ -27,6 +27,7 @@ kprobe_alloc(enum tracefs_dynevent_type type, const char *system, const char *ev
 	struct tracefs_dynevent *kp;
 	const char *sys = system;
 	const char *ename = event;
+	char *aname = NULL;
 	char *tmp;
 
 	if (!addr) {
@@ -37,17 +38,17 @@ kprobe_alloc(enum tracefs_dynevent_type type, const char *system, const char *ev
 		sys = KPROBE_DEFAULT_GROUP;
 
 	if (!event) {
-		ename = strdup(addr);
-		if (!ename)
+		aname = strdup(addr);
+		if (!aname)
 			return NULL;
-		tmp = strchr(ename, ':');
+		tmp = strchr(aname, ':');
 		if (tmp)
 			*tmp = '\0';
+		ename = aname;
 	}
 
 	kp = tfs_dynevent_alloc(type, sys, ename, addr, format);
-	if (!event)
-		free((char *)ename);
+	free(aname);
 
 	return kp;
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-08  8:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-08  8:48 [PATCH] libtracefs: Do not discard const ename for updating it Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.