diff mbox series

kernel-shark: sched-plugin: Initialize plugin_sched_context_handler to zeros

Message ID 20190214105635.3e0e1570@gandalf.local.home (mailing list archive)
State Accepted
Commit 1784290dba09e2606775d6a73bafdd2c4e16cd5a
Headers show
Series kernel-shark: sched-plugin: Initialize plugin_sched_context_handler to zeros | expand

Commit Message

Steven Rostedt Feb. 14, 2019, 3:56 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Now that the sched plugin only requires a single wakeup event to process the
wakeup latency boxes, there's no guarantee that all the wakeup events saved
in plugin_sched_context_handler will be initialized.

Allocate plugin_sched_context_handler to zeros with calloc() instead of
malloc() to make sure the pointers it has are NULL and not left
uninitialized.

Fixes: e50d3bbfc9a4 ("kernel-shark: Add sched_waking event processing to sched_waking")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel-shark/src/plugins/sched_events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Yordan Karadzhov Feb. 14, 2019, 4:33 p.m. UTC | #1
On 14.02.19 г. 17:56 ч., Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
> Now that the sched plugin only requires a single wakeup event to process the
> wakeup latency boxes, there's no guarantee that all the wakeup events saved
> in plugin_sched_context_handler will be initialized.
> 
> Allocate plugin_sched_context_handler to zeros with calloc() instead of
> malloc() to make sure the pointers it has are NULL and not left
> uninitialized.
> 
> Fixes: e50d3bbfc9a4 ("kernel-shark: Add sched_waking event processing to sched_waking")
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>   kernel-shark/src/plugins/sched_events.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel-shark/src/plugins/sched_events.c b/kernel-shark/src/plugins/sched_events.c
> index 14f8edb2..68734d4d 100644
> --- a/kernel-shark/src/plugins/sched_events.c
> +++ b/kernel-shark/src/plugins/sched_events.c
> @@ -49,7 +49,7 @@ static bool plugin_sched_init_context(struct kshark_context *kshark_ctx)
>   	assert(plugin_sched_context_handler == NULL);
>   
>   	plugin_sched_context_handler =
> -		malloc(sizeof(*plugin_sched_context_handler));
> +		calloc(1, sizeof(*plugin_sched_context_handler));
>   	if (!plugin_sched_context_handler) {
>   		fprintf(stderr,
>   			"Failed to allocate memory for plugin_sched_context.\n");
> 

makes perfect sense.

Thanks!
Yordan
Steven Rostedt Feb. 14, 2019, 4:36 p.m. UTC | #2
On Thu, 14 Feb 2019 16:33:03 +0000
Yordan Karadzhov <ykaradzhov@vmware.com> wrote:

> On 14.02.19 г. 17:56 ч., Steven Rostedt wrote:
> > From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> > 
> > Now that the sched plugin only requires a single wakeup event to process the
> > wakeup latency boxes, there's no guarantee that all the wakeup events saved
> > in plugin_sched_context_handler will be initialized.
> > 
> > Allocate plugin_sched_context_handler to zeros with calloc() instead of
> > malloc() to make sure the pointers it has are NULL and not left
> > uninitialized.
> > 
> > Fixes: e50d3bbfc9a4 ("kernel-shark: Add sched_waking event processing to sched_waking")
> > Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> > ---

> makes perfect sense.

Thanks Yordan,

Can you reply with an official "Reviewed-by" tag?

-- Steve
Yordan Karadzhov Feb. 14, 2019, 4:51 p.m. UTC | #3
On 14.02.19 г. 17:56 ч., Steven Rostedt wrote:
> From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
> 
> Now that the sched plugin only requires a single wakeup event to process the
> wakeup latency boxes, there's no guarantee that all the wakeup events saved
> in plugin_sched_context_handler will be initialized.
> 
> Allocate plugin_sched_context_handler to zeros with calloc() instead of
> malloc() to make sure the pointers it has are NULL and not left
> uninitialized.
> 
> Fixes: e50d3bbfc9a4 ("kernel-shark: Add sched_waking event processing to sched_waking")
> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> ---
>   kernel-shark/src/plugins/sched_events.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel-shark/src/plugins/sched_events.c b/kernel-shark/src/plugins/sched_events.c
> index 14f8edb2..68734d4d 100644
> --- a/kernel-shark/src/plugins/sched_events.c
> +++ b/kernel-shark/src/plugins/sched_events.c
> @@ -49,7 +49,7 @@ static bool plugin_sched_init_context(struct kshark_context *kshark_ctx)
>   	assert(plugin_sched_context_handler == NULL);
>   
>   	plugin_sched_context_handler =
> -		malloc(sizeof(*plugin_sched_context_handler));
> +		calloc(1, sizeof(*plugin_sched_context_handler));
>   	if (!plugin_sched_context_handler) {
>   		fprintf(stderr,
>   			"Failed to allocate memory for plugin_sched_context.\n");
> 

Reviewed-by: Yordan Karadzhov <ykaradzhov@vmware.com>
diff mbox series

Patch

diff --git a/kernel-shark/src/plugins/sched_events.c b/kernel-shark/src/plugins/sched_events.c
index 14f8edb2..68734d4d 100644
--- a/kernel-shark/src/plugins/sched_events.c
+++ b/kernel-shark/src/plugins/sched_events.c
@@ -49,7 +49,7 @@  static bool plugin_sched_init_context(struct kshark_context *kshark_ctx)
 	assert(plugin_sched_context_handler == NULL);
 
 	plugin_sched_context_handler =
-		malloc(sizeof(*plugin_sched_context_handler));
+		calloc(1, sizeof(*plugin_sched_context_handler));
 	if (!plugin_sched_context_handler) {
 		fprintf(stderr,
 			"Failed to allocate memory for plugin_sched_context.\n");