diff mbox series

[03/11] kernel-shark-qt: Avoid race condition in kshark_get_event_name_easy()

Message ID 20181121151356.16901-5-ykaradzhov@vmware.com (mailing list archive)
State Superseded
Headers show
Series Small modifications and bug fixes toward KS 1.0 | expand

Commit Message

Yordan Karadzhov Nov. 21, 2018, 3:14 p.m. UTC
Calling tep_data_event_from_type() is not thread-safe (potential
race condition). This patch protects the access to it by using the
mutex associated with the input file.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark-qt/src/libkshark.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Steven Rostedt Nov. 27, 2018, 8:37 p.m. UTC | #1
On Wed, 21 Nov 2018 15:14:21 +0000
Yordan Karadzhov <ykaradzhov@vmware.com> wrote:

> Calling tep_data_event_from_type() is not thread-safe (potential
> race condition). This patch protects the access to it by using the
> mutex associated with the input file.

Tzvetomir sent patches to handle the race condition here. I'll work to
apply his.

-- Steve

> 
> Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
> ---
>  kernel-shark-qt/src/libkshark.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/kernel-shark-qt/src/libkshark.c b/kernel-shark-qt/src/libkshark.c
> index fa85171..89ae769 100644
> --- a/kernel-shark-qt/src/libkshark.c
> +++ b/kernel-shark-qt/src/libkshark.c
> @@ -1147,7 +1147,18 @@ const char *kshark_get_event_name_easy(struct kshark_entry *entry)
>  		}
>  	}
>  
> +	/*
> +	 * Calling tep_data_event_from_type() is not thread-safe (potential
> +	 * race condition).
> +	 * TODO: See if we can add a thread-safe version of the
> +	 * function. For the time being use a mutex to protect the access.
> +	 */
> +	pthread_mutex_lock(&kshark_ctx->input_mutex);
> +
>  	event = tep_data_event_from_type(kshark_ctx->pevent, event_id);
> +
> +	pthread_mutex_unlock(&kshark_ctx->input_mutex);
> +
>  	if (event)
>  		return event->name;
>
diff mbox series

Patch

diff --git a/kernel-shark-qt/src/libkshark.c b/kernel-shark-qt/src/libkshark.c
index fa85171..89ae769 100644
--- a/kernel-shark-qt/src/libkshark.c
+++ b/kernel-shark-qt/src/libkshark.c
@@ -1147,7 +1147,18 @@  const char *kshark_get_event_name_easy(struct kshark_entry *entry)
 		}
 	}
 
+	/*
+	 * Calling tep_data_event_from_type() is not thread-safe (potential
+	 * race condition).
+	 * TODO: See if we can add a thread-safe version of the
+	 * function. For the time being use a mutex to protect the access.
+	 */
+	pthread_mutex_lock(&kshark_ctx->input_mutex);
+
 	event = tep_data_event_from_type(kshark_ctx->pevent, event_id);
+
+	pthread_mutex_unlock(&kshark_ctx->input_mutex);
+
 	if (event)
 		return event->name;