diff mbox series

[01/24] kernel-shark: Add get_stream_object()

Message ID 20210201172358.175407-2-y.karadz@gmail.com (mailing list archive)
State Superseded
Headers show
Series Complete the KernelShark v2 transformation | expand

Commit Message

Yordan Karadzhov Feb. 1, 2021, 5:23 p.m. UTC
In a previous patch we modified kshark_get_data_stream() to return
NULL in the case when the kshark_data_stream object does not own
a data processing interface. This was motivated by the idea that
kshark_get_data_stream() is supposed to be used to access only
successfully loaded data streams, which is not possible in the case
when the data processing interface is not initialized. However, this
creates a contradiction with the definition of the public method
kshark_add_stream(). This method adds a stream without initializing
its data processing interface. In this patch we add a static function
that returns the Data stream object, regardless of the existence of
the interface and we use this static function in all cases when the
existence of the interface is not guaranteed.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 src/libkshark.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/libkshark.c b/src/libkshark.c
index a54fdd5..c57ca01 100644
--- a/src/libkshark.c
+++ b/src/libkshark.c
@@ -361,6 +361,17 @@  kshark_get_data_stream(struct kshark_context *kshark_ctx, int sd)
 	return NULL;
 }
 
+static struct kshark_data_stream *
+get_stream_object(struct kshark_context *kshark_ctx, int sd)
+{
+	if (sd >= 0 && sd <= kshark_ctx->stream_info.max_stream_id)
+		if (kshark_ctx->stream[sd] &&
+		    kshark_is_valid_stream(kshark_ctx->stream[sd]))
+			return kshark_ctx->stream[sd];
+
+	return NULL;
+}
+
 /**
  * @brief Get the Data stream object corresponding to a given entry
  *
@@ -443,7 +454,7 @@  int kshark_close(struct kshark_context *kshark_ctx, int sd)
 	struct kshark_data_stream *stream;
 	int ret;
 
-	stream = kshark_get_data_stream(kshark_ctx, sd);
+	stream = get_stream_object(kshark_ctx, sd);
 	if (!stream)
 		return -EFAULT;
 
@@ -1182,7 +1193,7 @@  bool kshark_filter_is_set(struct kshark_context *kshark_ctx, int sd)
 {
 	struct kshark_data_stream *stream;
 
-	stream = kshark_get_data_stream(kshark_ctx, sd);
+	stream = get_stream_object(kshark_ctx, sd);
 	if (!stream)
 		return false;