From patchwork Sat Apr 9 11:57:58 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pekka Enberg X-Patchwork-Id: 695871 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p39Bw5rZ002100 for ; Sat, 9 Apr 2011 11:58:05 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754253Ab1DIL6C (ORCPT ); Sat, 9 Apr 2011 07:58:02 -0400 Received: from filtteri2.pp.htv.fi ([213.243.153.185]:48463 "EHLO filtteri2.pp.htv.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753282Ab1DIL6B (ORCPT ); Sat, 9 Apr 2011 07:58:01 -0400 Received: from localhost (localhost [127.0.0.1]) by filtteri2.pp.htv.fi (Postfix) with ESMTP id 09D7B19B4B1; Sat, 9 Apr 2011 14:58:00 +0300 (EEST) X-Virus-Scanned: Debian amavisd-new at pp.htv.fi Received: from smtp5.welho.com ([213.243.153.39]) by localhost (filtteri2.pp.htv.fi [213.243.153.185]) (amavisd-new, port 10024) with ESMTP id 0doF+8m8a6FO; Sat, 9 Apr 2011 14:57:59 +0300 (EEST) Received: from localhost.localdomain (cs181148025.pp.htv.fi [82.181.148.25]) by smtp5.welho.com (Postfix) with ESMTP id 8BF3F5BC003; Sat, 9 Apr 2011 14:57:59 +0300 (EEST) From: Pekka Enberg To: kvm@vger.kernel.org Cc: Pekka Enberg , Asias He , Cyrill Gorcunov , Ingo Molnar Subject: [PATCH] kvm tools: Fix pthread mutex error checks Date: Sat, 9 Apr 2011 14:57:58 +0300 Message-Id: <1302350278-5478-1-git-send-email-penberg@kernel.org> X-Mailer: git-send-email 1.7.0.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sat, 09 Apr 2011 11:58:05 +0000 (UTC) The pthread_mutex_{lock|unlock} functions return non-zero, not negative number upon error. Fix that wrong assumption in the code. Cc: Asias He Cc: Cyrill Gorcunov Cc: Ingo Molnar Signed-off-by: Pekka Enberg --- tools/kvm/8250-serial.c | 12 ++++++------ tools/kvm/virtio-blk.c | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/kvm/8250-serial.c b/tools/kvm/8250-serial.c index 3395f85..9394e88 100644 --- a/tools/kvm/8250-serial.c +++ b/tools/kvm/8250-serial.c @@ -116,7 +116,7 @@ void serial8250__inject_interrupt(struct kvm *self) { struct serial8250_device *dev = &devices[0]; - if (pthread_mutex_lock(&dev->mutex) < 0) + if (pthread_mutex_lock(&dev->mutex) != 0) die("pthread_mutex_lock"); serial8250__receive(self, dev); @@ -133,7 +133,7 @@ void serial8250__inject_interrupt(struct kvm *self) kvm__irq_line(self, dev->irq, 1); } - if (pthread_mutex_unlock(&dev->mutex) < 0) + if (pthread_mutex_unlock(&dev->mutex) != 0) die("pthread_mutex_unlock"); } @@ -165,7 +165,7 @@ static bool serial8250_out(struct kvm *self, uint16_t port, void *data, int size if (!dev) return false; - if (pthread_mutex_lock(&dev->mutex) < 0) + if (pthread_mutex_lock(&dev->mutex) != 0) die("pthread_mutex_lock"); offset = port - dev->iobase; @@ -239,7 +239,7 @@ static bool serial8250_out(struct kvm *self, uint16_t port, void *data, int size } out_unlock: - if (pthread_mutex_unlock(&dev->mutex) < 0) + if (pthread_mutex_unlock(&dev->mutex) != 0) die("pthread_mutex_unlock"); return ret; @@ -255,7 +255,7 @@ static bool serial8250_in(struct kvm *self, uint16_t port, void *data, int size, if (!dev) return false; - if (pthread_mutex_lock(&dev->mutex) < 0) + if (pthread_mutex_lock(&dev->mutex) != 0) die("pthread_mutex_lock"); offset = port - dev->iobase; @@ -321,7 +321,7 @@ static bool serial8250_in(struct kvm *self, uint16_t port, void *data, int size, goto out_unlock; } out_unlock: - if (pthread_mutex_unlock(&dev->mutex) < 0) + if (pthread_mutex_unlock(&dev->mutex) != 0) die("pthread_mutex_unlock"); return ret; diff --git a/tools/kvm/virtio-blk.c b/tools/kvm/virtio-blk.c index 8f1c684..5e7f57d 100644 --- a/tools/kvm/virtio-blk.c +++ b/tools/kvm/virtio-blk.c @@ -70,7 +70,7 @@ static bool virtio_blk_pci_io_in(struct kvm *self, uint16_t port, void *data, in unsigned long offset; bool ret = true; - if (pthread_mutex_lock(&blk_device.mutex) < 0) + if (pthread_mutex_lock(&blk_device.mutex) != 0) die("pthread_mutex_lock"); offset = port - IOPORT_VIRTIO_BLK; @@ -108,7 +108,7 @@ static bool virtio_blk_pci_io_in(struct kvm *self, uint16_t port, void *data, in }; out_unlock: - if (pthread_mutex_unlock(&blk_device.mutex) < 0) + if (pthread_mutex_unlock(&blk_device.mutex) != 0) die("pthread_mutex_unlock"); return ret; @@ -180,7 +180,7 @@ static bool virtio_blk_pci_io_out(struct kvm *self, uint16_t port, void *data, i unsigned long offset; bool ret = true; - if (pthread_mutex_lock(&blk_device.mutex) < 0) + if (pthread_mutex_lock(&blk_device.mutex) != 0) die("pthread_mutex_lock"); offset = port - IOPORT_VIRTIO_BLK; @@ -226,7 +226,7 @@ static bool virtio_blk_pci_io_out(struct kvm *self, uint16_t port, void *data, i }; out_unlock: - if (pthread_mutex_unlock(&blk_device.mutex) < 0) + if (pthread_mutex_unlock(&blk_device.mutex) != 0) die("pthread_mutex_unlock"); return ret;