From: Pekka Enberg <penberg@kernel.org>
To: kvm@vger.kernel.org
Cc: Pekka Enberg <penberg@kernel.org>,
Asias He <asias.hejun@gmail.com>,
Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>
Subject: [PATCH] kvm tools: Fix pthread mutex error checks
Date: Sat, 9 Apr 2011 14:57:58 +0300 [thread overview]
Message-ID: <1302350278-5478-1-git-send-email-penberg@kernel.org> (raw)
The pthread_mutex_{lock|unlock} functions return non-zero, not negative number
upon error. Fix that wrong assumption in the code.
Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
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;
--
1.7.0.4
next reply other threads:[~2011-04-09 11:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-09 11:57 Pekka Enberg [this message]
2011-04-09 13:15 ` [PATCH] kvm tools: Fix pthread mutex error checks Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1302350278-5478-1-git-send-email-penberg@kernel.org \
--to=penberg@kernel.org \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox