]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: if kvm_ipc__start failed, return negative
authorYang Bai <hamo.by@gmail.com>
Fri, 10 Feb 2012 09:55:35 +0000 (17:55 +0800)
committerPekka Enberg <penberg@kernel.org>
Fri, 10 Feb 2012 11:37:23 +0000 (13:37 +0200)
If kvm_ipc__start failed, it returns a negative and by checking
this return value, we can ensure that it succeeds.

Signed-off-by: Yang Bai <hamo.by@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/kvm-ipc.c
tools/kvm/kvm.c

index 6a0bd215a8175659d2b4a9a963cc474ab1031bd9..257c806cf191841c252f7e2b9a04a1c8855c2e9b 100644 (file)
@@ -166,27 +166,53 @@ static void *kvm_ipc__thread(void *param)
 
 int kvm_ipc__start(int sock)
 {
+       int ret;
        struct epoll_event ev = {0};
 
        server_fd = sock;
 
        epoll_fd = epoll_create(KVM_IPC_MAX_MSGS);
+       if (epoll_fd < 0) {
+               ret = epoll_fd;
+               goto err;
+       }
 
        ev.events = EPOLLIN | EPOLLET;
        ev.data.fd = sock;
-       if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) < 0)
-               die("Failed starting IPC thread");
+       if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev) < 0) {
+               pr_err("Failed starting IPC thread");
+               ret = -EFAULT;
+               goto err_epoll;
+       }
 
        stop_fd = eventfd(0, 0);
+       if (stop_fd < 0) {
+               ret = stop_fd;
+               goto err_epoll;
+       }
+
        ev.events = EPOLLIN | EPOLLET;
        ev.data.fd = stop_fd;
-       if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_fd, &ev) < 0)
-               die("Failed adding stop event to epoll");
+       if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, stop_fd, &ev) < 0) {
+               pr_err("Failed adding stop event to epoll");
+               ret = -EFAULT;
+               goto err_stop;
+       }
 
-       if (pthread_create(&thread, NULL, kvm_ipc__thread, NULL) != 0)
-               die("Failed starting IPC thread");
+       if (pthread_create(&thread, NULL, kvm_ipc__thread, NULL) != 0) {
+               pr_err("Failed starting IPC thread");
+               ret = -EFAULT;
+               goto err_stop;
+       }
 
        return 0;
+
+err_stop:
+       close(stop_fd);
+err_epoll:
+       close(epoll_fd);
+err:
+       return ret;
 }
 
 int kvm_ipc__stop(void)
index 192d70eddf84e963c57db248aea3191ab34d2ee5..f02d5dffedc890b0195537431e159b5e7cca04fa 100644 (file)
@@ -390,7 +390,12 @@ struct kvm *kvm__init(const char *kvm_dev, const char *hugetlbfs_path, u64 ram_s
 
        kvm__arch_init(kvm, hugetlbfs_path, ram_size);
 
-       kvm_ipc__start(kvm__create_socket(kvm));
+       ret = kvm_ipc__start(kvm__create_socket(kvm));
+       if (ret < 0) {
+               pr_err("Starting ipc failed.");
+               goto err_vm_fd;
+       }
+
        kvm_ipc__register_handler(KVM_IPC_PID, kvm__pid);
 
        return kvm;