diff mbox series

[3/4] libtracefs: Check tracer parameter first in tracefs_tracer_set()

Message ID 20210625221739.1215557-4-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 69ec978b158fbf61291465932f808f91b4c5ae9d
Headers show
Series libtracefs: Updates to tracefs_tracer_set() | expand

Commit Message

Steven Rostedt June 25, 2021, 10:17 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

There's no reason to open the current_tracer file, nor even find its path
before checking if the tracer parameter is valid or not. Instead of
checking that later in the process and then having to "clean up" what has
already been done, check it first, and simply return with error if it is
not valid.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 src/tracefs-tools.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index 6d5ddae..0e689aa 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -973,6 +973,11 @@  int tracefs_tracer_set(struct tracefs_instance *instance,
 	int fd = -1;
 	int i;
 
+	if (tracer < 0 || tracer > ARRAY_SIZE(tracers)) {
+		errno = EINVAL;
+		return -1;
+	}
+
 	tracer_path = tracefs_instance_get_file(instance, CUR_TRACER);
 	if (!tracer_path)
 		return -1;
@@ -983,11 +988,6 @@  int tracefs_tracer_set(struct tracefs_instance *instance,
 		goto out;
 	}
 
-	if (tracer < 0 || tracer > ARRAY_SIZE(tracers)) {
-		errno = EINVAL;
-		goto out;
-	}
-
 	if (tracer == TRACEFS_TRACER_CUSTOM) {
 		va_list ap;