diff mbox series

[4/7] libtracefs: Fix tracefs_mmap() kbuf usage

Message ID 20240110030116.81837-5-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit cf7e2a5b5b06c8aa5230bae661c082059b6287c3
Headers show
Series libtracefs: More fixes for memory mapping ring buffer API | expand

Commit Message

Steven Rostedt Jan. 10, 2024, 2:51 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

The tracefs_mmap() function used the "kbuf" variable instead of the
"tmap->kbuf" variable which caused confusion later on.

The kbuf passed in is only used to make the "duplicate" for tmap->kbuf, so
once that is done, just assign kbuf = tmap->kbuf and use "kbuf" throughout
the rest of the function to avoid confusion.

Fixes: 2ed14b594f669 ("libtracefs: Add ring buffer memory mapping APIs")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 src/tracefs-mmap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/tracefs-mmap.c b/src/tracefs-mmap.c
index f481bda37eaf..e0e37681e019 100644
--- a/src/tracefs-mmap.c
+++ b/src/tracefs-mmap.c
@@ -81,6 +81,7 @@  __hidden void *trace_mmap(int fd, struct kbuffer *kbuf)
 		munmap(meta, page_size);
 		free(tmap);
 	}
+	kbuf = tmap->kbuf;
 
 	tmap->fd = fd;
 
@@ -91,7 +92,7 @@  __hidden void *trace_mmap(int fd, struct kbuffer *kbuf)
 		munmap(meta, page_size);
 		meta = mmap(NULL, tmap->meta_len, PROT_READ, MAP_SHARED, fd, 0);
 		if (meta == MAP_FAILED) {
-			kbuffer_free(tmap->kbuf);
+			kbuffer_free(kbuf);
 			free(tmap);
 			return NULL;
 		}
@@ -106,7 +107,7 @@  __hidden void *trace_mmap(int fd, struct kbuffer *kbuf)
 			  fd, tmap->meta_len);
 	if (tmap->data == MAP_FAILED) {
 		munmap(meta, tmap->meta_len);
-		kbuffer_free(tmap->kbuf);
+		kbuffer_free(kbuf);
 		free(tmap);
 		return NULL;
 	}