aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/vhost
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2011-01-10 03:03:20 -0500
committerMichael S. Tsirkin <mst@redhat.com>2011-01-10 03:03:39 -0500
commit0174b0c30a9de25dcb0d3049defcfad0c2947a36 (patch)
treec7d4430ea5f83b52c9074df6770ad6281735bbc3 /drivers/vhost
parent0c21e3aaf6ae85bee804a325aa29c325209180fd (diff)
vhost: fix signed/unsigned comparison
To detect that a sequence number is done, we are doing math on unsigned integers so the result is unsigned too. Not what was intended for the <= comparison. The result is user stuck forever in flush call. Convert to int to fix this. Further, get rid of ({}) to make code clearer. Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'drivers/vhost')
-rw-r--r--drivers/vhost/vhost.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 38244f59cdd..ade0568c07a 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -97,22 +97,26 @@ void vhost_poll_stop(struct vhost_poll *poll)
97 remove_wait_queue(poll->wqh, &poll->wait); 97 remove_wait_queue(poll->wqh, &poll->wait);
98} 98}
99 99
100static bool vhost_work_seq_done(struct vhost_dev *dev, struct vhost_work *work,
101 unsigned seq)
102{
103 int left;
104 spin_lock_irq(&dev->work_lock);
105 left = seq - work->done_seq;
106 spin_unlock_irq(&dev->work_lock);
107 return left <= 0;
108}
109
100static void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work) 110static void vhost_work_flush(struct vhost_dev *dev, struct vhost_work *work)
101{ 111{
102 unsigned seq; 112 unsigned seq;
103 int left;
104 int flushing; 113 int flushing;
105 114
106 spin_lock_irq(&dev->work_lock); 115 spin_lock_irq(&dev->work_lock);
107 seq = work->queue_seq; 116 seq = work->queue_seq;
108 work->flushing++; 117 work->flushing++;
109 spin_unlock_irq(&dev->work_lock); 118 spin_unlock_irq(&dev->work_lock);
110 wait_event(work->done, ({ 119 wait_event(work->done, vhost_work_seq_done(dev, work, seq));
111 spin_lock_irq(&dev->work_lock);
112 left = seq - work->done_seq <= 0;
113 spin_unlock_irq(&dev->work_lock);
114 left;
115 }));
116 spin_lock_irq(&dev->work_lock); 120 spin_lock_irq(&dev->work_lock);
117 flushing = --work->flushing; 121 flushing = --work->flushing;
118 spin_unlock_irq(&dev->work_lock); 122 spin_unlock_irq(&dev->work_lock);