From 7c6f853dc109ea0493bce8652f9531c416967600 Mon Sep 17 00:00:00 2001 From: matteo serva Date: Tue, 5 Mar 2024 22:33:18 +0100 Subject: [PATCH] fixing spurious wakeup while waiting for write pipe --- driver/smi_stream_dev.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/driver/smi_stream_dev.c b/driver/smi_stream_dev.c index bb6af44..ef915b6 100644 --- a/driver/smi_stream_dev.c +++ b/driver/smi_stream_dev.c @@ -764,7 +764,6 @@ void transfer_thread_stop(struct bcm2835_smi_dev_instance *inst) static int smi_stream_open(struct inode *inode, struct file *file) { - int ret; int dev = iminor(inode); dev_dbg(inst->dev, "SMI device opened."); @@ -888,13 +887,18 @@ static ssize_t smi_stream_write_file(struct file *f, const char __user *user_ptr if (mutex_lock_interruptible(&inst->write_lock)) { - return -EINTR; + return -EAGAIN; } if (kfifo_is_full(&inst->tx_fifo)) { - mutex_unlock(&inst->write_lock); - return -EAGAIN; + if(wait_event_interruptible(inst->poll_event, !kfifo_is_full(&inst->tx_fifo))) + { + mutex_unlock(&inst->write_lock); + return -EAGAIN; + } + + } // check how many bytes are available in the tx fifo @@ -915,14 +919,14 @@ static unsigned int smi_stream_poll(struct file *filp, struct poll_table_struct poll_wait(filp, &inst->poll_event, wait); - if (inst->readable || !kfifo_is_empty(&inst->rx_fifo)) + if (!kfifo_is_empty(&inst->rx_fifo)) { //dev_info(inst->dev, "poll_wait result => readable=%d", inst->readable); inst->readable = false; mask |= ( POLLIN | POLLRDNORM ); } - if (inst->writeable) + if (!kfifo_is_full(&inst->rx_fifo)) { //dev_info(inst->dev, "poll_wait result => writeable=%d", inst->writeable); inst->writeable = false;