From 8e0a4cf6eda7ee9796a94571224bcfed4472c7b6 Mon Sep 17 00:00:00 2001 From: David Cuthbert Date: Fri, 25 Dec 2015 02:24:04 -0800 Subject: [PATCH] Fix lockup with poll. --- src/ublkdev.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ublkdev.c b/src/ublkdev.c index 7b7ef3f..1ad445f 100644 --- a/src/ublkdev.c +++ b/src/ublkdev.c @@ -474,24 +474,26 @@ static unsigned int ubdctl_poll(struct file *filp, poll_table *wait) { } else { unsigned long lock_flags; uint32_t status; + wait_queue_head_t *wq; + struct request *pending_delivery; spin_lock_irqsave(&dev->wait.lock, lock_flags); status = ACCESS_ONCE(dev->status); - - poll_wait(filp, &dev->wait, wait); + wq = &dev->wait; + pending_delivery = ACCESS_ONCE(dev->pending_delivery_head); + spin_unlock_irqrestore(&dev->wait.lock, lock_flags); if (status == UBD_STATUS_RUNNING) { + poll_wait(filp, wq, wait); result |= POLLOUT | POLLWRNORM; - if (dev->pending_delivery_head != NULL) { + if (pending_delivery != NULL) { result |= POLLIN | POLLRDNORM; } } else if (status == UBD_STATUS_TERMINATED) { /* Device is being torn down. */ result |= POLLHUP; } - - spin_unlock_irqrestore(&dev->wait.lock, lock_flags); } return result; @@ -503,9 +505,6 @@ static long ubdctl_ioctl( unsigned int cmd, unsigned long data) { - printk(KERN_DEBUG "[%d] ubdctl_ioctl: ioctl(%u, 0x%lx)\n", - current->pid, cmd, data); - switch (cmd) { case UBD_IOCREGISTER: return ubdctl_ioctl_register(filp, cmd, data);