diff mbox series

[2/2] libtracefs: Reset errno to success on EAGAIN for the flush functions

Message ID 20221110225959.2285998-3-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 01d683a36602dbd831f61d8842b6a00ed0496de6
Headers show
Series libtracefs: Handle EAGAIN case in flush functions | expand

Commit Message

Steven Rostedt Nov. 10, 2022, 10:59 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The functions tracefs_cpu_flush() and tracefs_cpu_flush_write() both
usually end with errno = EAGAIN. This should not be passed to the calling
function, so reset it to 0.

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

Patch

diff --git a/src/tracefs-record.c b/src/tracefs-record.c
index 71d1df99bb02..428bec0dfe3d 100644
--- a/src/tracefs-record.c
+++ b/src/tracefs-record.c
@@ -308,8 +308,11 @@  int tracefs_cpu_read(struct tracefs_cpu *tcpu, void *buffer, bool nonblock)
 	ret = read(tcpu->fd, buffer, tcpu->subbuf_size);
 
 	/* It's OK if there's no data to read */
-	if (ret < 0 && errno == EAGAIN)
+	if (ret < 0 && errno == EAGAIN) {
+		/* Reset errno */
+		errno = 0;
 		ret = 0;
+	}
 
 	return ret;
 }
@@ -470,8 +473,11 @@  int tracefs_cpu_flush(struct tracefs_cpu *tcpu, void *buffer)
 		tcpu->buffered -= ret;
 
 	/* It's OK if there's no data to read */
-	if (ret < 0 && errno == EAGAIN)
+	if (ret < 0 && errno == EAGAIN) {
+		/* Reset errno */
+		errno = 0;
 		ret = 0;
+	}
 
 	return ret;
 }