Skip to contentSkip to conversation

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

PATCH In review Steven Rostedt 2 participants 4 messages Feb 14, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel-shark: sched-plugin: Initialize plugin_sched_context_handler to zeros

From: "Steven Rostedt (VMware)" <[email protected]>

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")
---
 kernel-shark/src/plugins/sched_events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel-shark/src/plugins/sched_events.c +1 -1
index 14f8edb2..68734d4d 100644
@@ -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");
Signature · 1 line
2.20.1
#1 lore raw
Quoted 22 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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")
---
  kernel-shark/src/plugins/sched_events.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel-shark/src/plugins/sched_events.c +0 -0
index 14f8edb2..68734d4d 100644

kernel-shark/src/plugins/sched_events.c static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) · line 55

Quoted 8 lines
kernel-shark/src/plugins/sched_events.c +1 -1
@@ -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

#2 lore raw
Quoted 11 lines · On Thu, 14 Feb 2019 16:33:03 +0000 Yordan Karadzhov <[email protected]>…
Quoted 10 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

Quoted 5 lines
Quoted 3 lines
Fixes e50d3bbfc9a4 ("kernel-shark: Add sched_waking event processing to sched_waking")

---

makes perfect sense.

Thanks Yordan,

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

-- Steve

Reviewed-by on v1 1/1
#3 lore raw
In reply to Steven Rostedt
Quoted 22 lines · Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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")
---
  kernel-shark/src/plugins/sched_events.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
kernel-shark/src/plugins/sched_events.c +0 -0
index 14f8edb2..68734d4d 100644

kernel-shark/src/plugins/sched_events.c static bool plugin_sched_init_context(struct kshark_context *kshark_ctx) · line 55

Quoted 8 lines
kernel-shark/src/plugins/sched_events.c +1 -1
@@ -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");