kvm tools: Fix pthread mutex error checks

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>
This commit is contained in:
Pekka Enberg
2015-06-01 16:39:42 +01:00
committed by Will Deacon
parent a2a002f91b
commit 04d76d8673
2 changed files with 10 additions and 10 deletions
+6 -6
View File
@@ -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;
+4 -4
View File
@@ -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;