[PATCH 5/8] char: xillybus: Refactor flush function
From: Eli Billauer
Date: Mon Nov 09 2026 - 06:33:15 EST
Previous flush_downstream() looped on wait_event_interruptible() and
wait_event_interruptible_timeout() without returning if an interrupt
occurred. Replace these with non-interruptible counterparts and use
wake_up() instead of wake_up_interruptible() on the relevant wait queue.
In addition, flush_downstream()'s @interruptible argument is removed.
Instead, this function either waits with a timeout only, or with an
interruptible wait. This is what the callers of this function requested
anyhow.
Assisted-by: Sashiko-0.2.5:gemini-3.1-pro-preview
Link: https://sashiko.dev/#/patchset/20260724094302.50761-1-eli.billauer@xxxxxxxxx
Signed-off-by: Eli Billauer <eli.billauer@xxxxxxxxx>
---
drivers/char/xillybus/xillyusb.c | 89 +++++++++++++++-----------------
1 file changed, 41 insertions(+), 48 deletions(-)
diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
index 73e26f254693..3afd9bd38a1a 100644
--- a/drivers/char/xillybus/xillyusb.c
+++ b/drivers/char/xillybus/xillyusb.c
@@ -604,7 +604,7 @@ static void wakeup_all(struct work_struct *work)
mutex_unlock(&chan->lock);
- wake_up_interruptible(&chan->flushq);
+ wake_up(&chan->flushq);
}
mutex_unlock(&xdev->process_in_mutex);
@@ -923,12 +923,12 @@ static int process_in_opcode(struct xillyusb_dev *xdev,
case OPCODE_REACHED_CHECKPOINT:
chan->flushing = 0;
- wake_up_interruptible(&chan->flushq);
+ wake_up(&chan->flushq);
break;
case OPCODE_CANCELED_CHECKPOINT:
chan->canceled = 1;
- wake_up_interruptible(&chan->flushq);
+ wake_up(&chan->flushq);
break;
default:
@@ -1130,11 +1130,13 @@ static int xillyusb_send_opcode(struct xillyusb_dev *xdev,
* chan->flushed is there to avoid multiple flushes at the same position,
* in particular as a result of programs that close the file descriptor
* e.g. after a dup2() for redirection.
+ *
+ * If timeout == 0, no timeout is applied and the wait is interruptible,
+ * otherwise a timeout is applied but the wait is non-interruptible.
*/
static int flush_downstream(struct xillyusb_channel *chan,
- unsigned long timeout,
- bool interruptible)
+ unsigned long timeout)
{
struct xillyusb_dev *xdev = chan->xdev;
int chan_num = chan->chan_idx << 1;
@@ -1159,21 +1161,22 @@ static int flush_downstream(struct xillyusb_channel *chan,
return rc; /* Only real error, never -EINTR */
/* Ignoring interrupts. Cancellation must be handled */
- while (!chan->canceled) {
- left_to_sleep = cancel_deadline - jiffies;
+ left_to_sleep = cancel_deadline - jiffies;
- if (left_to_sleep <= 0) {
- report_io_error(xdev, -EIO);
- return -EIO;
- }
+ rc = 0;
- rc = wait_event_interruptible_timeout(chan->flushq,
- chan->canceled ||
- xdev->error,
- left_to_sleep);
+ if (left_to_sleep > 0)
+ rc = wait_event_timeout(chan->flushq,
+ chan->canceled ||
+ xdev->error,
+ left_to_sleep);
+
+ if (xdev->error)
+ return xdev->error;
- if (xdev->error)
- return xdev->error;
+ if (!rc) {
+ report_io_error(xdev, -EIO);
+ return -EIO;
}
}
@@ -1194,40 +1197,30 @@ static int flush_downstream(struct xillyusb_channel *chan,
if (rc)
return rc; /* Only real error, never -EINTR */
- if (!timeout) {
- while (chan->flushing) {
- rc = wait_event_interruptible(chan->flushq,
- !chan->flushing ||
- xdev->error);
- if (xdev->error)
- return xdev->error;
-
- if (interruptible && rc)
- return -EINTR;
- }
+ if (timeout) {
+ left_to_sleep = deadline - jiffies;
- goto done;
- }
+ rc = 0;
- while (chan->flushing) {
- left_to_sleep = deadline - jiffies;
+ if (left_to_sleep > 0)
+ rc = wait_event_timeout(chan->flushq,
+ !chan->flushing ||
+ xdev->error,
+ left_to_sleep);
- if (left_to_sleep <= 0)
+ if (!rc)
return -ETIMEDOUT;
+ } else {
+ rc = wait_event_interruptible(chan->flushq,
+ !chan->flushing || xdev->error);
+ }
- rc = wait_event_interruptible_timeout(chan->flushq,
- !chan->flushing ||
- xdev->error,
- left_to_sleep);
-
- if (xdev->error)
- return xdev->error;
+ if (xdev->error)
+ return xdev->error;
- if (interruptible && rc < 0)
- return -EINTR;
- }
+ if (rc < 0)
+ return -EINTR;
-done:
chan->flushed = 1;
return 0;
}
@@ -1335,7 +1328,7 @@ static int xillyusb_open(struct inode *inode, struct file *filp)
* This can't go wrong unless there's a serious hardware error
* (or the computer is stuck for 500 ms?)
*/
- rc = flush_downstream(chan, XILLY_RESPONSE_TIMEOUT, false);
+ rc = flush_downstream(chan, XILLY_RESPONSE_TIMEOUT);
if (rc == -ETIMEDOUT) {
rc = -EIO;
@@ -1629,7 +1622,7 @@ static int xillyusb_flush(struct file *filp, fl_owner_t id)
* the user pressed CTRL-C, that interrupt will still be in flight by
* the time we reach here, and the opportunity to flush is lost.
*/
- rc = flush_downstream(chan, HZ, false);
+ rc = flush_downstream(chan, HZ);
mutex_unlock(&chan->out_mutex);
@@ -1699,7 +1692,7 @@ static ssize_t xillyusb_write(struct file *filp, const char __user *userbuf,
}
if (chan->out_synchronous) {
- int flush_rc = flush_downstream(chan, 0, true);
+ int flush_rc = flush_downstream(chan, 0);
if (flush_rc && !rc)
rc = flush_rc;
@@ -1836,7 +1829,7 @@ static loff_t xillyusb_llseek(struct file *filp, loff_t offset, int whence)
if (chan->writable) {
chan->flushed = 0;
- rc = flush_downstream(chan, HZ, false);
+ rc = flush_downstream(chan, HZ);
}
end:
--
2.17.1