Skip to contentSkip to conversation

kvm tools: Zero out event before calling epoll_ctl()

PATCH In review Sasha Levin 2 participants 3 messages Dec 6, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 kvm tools: Zero out event before calling epoll_ctl()

Zero out struct epoll_event before calling epoll_ctl(). This isn't really required, but is done to avoid warnings.

---
 tools/kvm/kvm-ipc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/kvm/kvm-ipc.c +1 -1
index 40ab457..68c2565 100644
@@ -132,7 +132,7 @@ static void *kvm_ipc__thread(void *param)
 
 int kvm_ipc__start(int sock)
 {
-	struct epoll_event ev;
+	struct epoll_event ev = {0};
 
 	server_fd = sock;
 
Signature · 1 line
1.7.8
#1 lore raw

PATCH 2/2 kvm tools: Initialize irq_routing before using it

Initialize irq_routing, and specifically irq_routing->nr before using it.

---
 tools/kvm/x86/irq.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tools/kvm/x86/irq.c +2 -2
index 1392dfb..b8a7257 100644
@@ -140,8 +140,8 @@ void irq__init(struct kvm *kvm)
 {
 	int i, r;
 
-	irq_routing = malloc(sizeof(struct kvm_irq_routing) +
-			IRQ_MAX_GSI * sizeof(struct kvm_irq_routing_entry));
+	irq_routing = calloc(sizeof(struct kvm_irq_routing) +
+			IRQ_MAX_GSI * sizeof(struct kvm_irq_routing_entry), 1);
 	if (irq_routing == NULL)
 		die("Failed allocating space for GSI table");
 
Signature · 1 line
1.7.8
#2 lore raw
In reply to Sasha Levin
Quoted 13 lines · Sasha Levin

Zero out struct epoll_event before calling epoll_ctl(). This isn't really required, but is done to avoid warnings.

---
 tools/kvm/kvm-ipc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/kvm/kvm-ipc.c +0 -0
index 40ab457..68c2565 100644

tools/kvm/kvm-ipc.c static void *kvm_ipc__thread(void *param) · line 137

Quoted 7 lines
tools/kvm/kvm-ipc.c +1 -1
@@ -132,7 +132,7 @@ static void *kvm_ipc__thread(void *param)
 
 int kvm_ipc__start(int sock)
 {
-	struct epoll_event ev;
+	struct epoll_event ev = {0};
 
 	server_fd = sock;

While it is true that epoll_ctl() currently ignores certain fields so we could leave them uninitialized but generally it's very good practice to only pass in well-defined values to kernel syscalls, so the zeroing is a quality of implementation issue as well, not just a Valgrind warning fix.

Thanks,

Ingo