From: Eli Billauer <eli.billauer@gmail.com>
To: gregkh@linuxfoundation.org
Cc: arnd@arndb.de, linux-kernel@vger.kernel.org,
Eli Billauer <eli.billauer@gmail.com>
Subject: [PATCH v2 5/8] char: xillybus: Refactor flush function
Date: Tue, 17 Nov 2026 12:58:59 +0100 [thread overview]
Message-ID: <20261117115902.41359-6-eli.billauer@gmail.com> (raw)
In-Reply-To: <20261117115902.41359-1-eli.billauer@gmail.com>
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.
Fixes: a53d1202aef1 ("char: xillybus: Add driver for XillyUSB (Xillybus variant for USB)")
Assisted-by: Sashiko-0.2.5:gemini-3.1-pro-preview
Link: https://sashiko.dev/#/patchset/20260724094302.50761-1-eli.billauer@gmail.com
Link: https://sashiko.dev/#/patchset/20261109112800.48663-1-eli.billauer@gmail.com
Signed-off-by: Eli Billauer <eli.billauer@gmail.com>
---
Notes:
Changes in v2:
- Always call wait_event_timeout(), with a timeout of max(1L,
left_to_sleep), so that the wait condition is checked even when the
deadline has already passed. This addresses Sashiko's comment about
a missing condition check in flush_downstream().
- Added include of <linux/minmax.h> for max().
- Added Fixes: tag.
drivers/char/xillybus/xillyusb.c | 86 ++++++++++++++------------------
1 file changed, 37 insertions(+), 49 deletions(-)
diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
index f9c8591a679f..decc87f8e059 100644
--- a/drivers/char/xillybus/xillyusb.c
+++ b/drivers/char/xillybus/xillyusb.c
@@ -12,6 +12,7 @@
*/
#include <linux/types.h>
+#include <linux/minmax.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/device.h>
@@ -601,7 +602,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);
@@ -920,12 +921,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:
@@ -1127,11 +1128,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;
@@ -1156,21 +1159,19 @@ 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 = wait_event_timeout(chan->flushq,
+ chan->canceled ||
+ xdev->error,
+ max(1L, left_to_sleep));
- rc = wait_event_interruptible_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;
}
}
@@ -1191,40 +1192,27 @@ 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;
- }
-
- goto done;
- }
-
- while (chan->flushing) {
+ if (timeout) {
left_to_sleep = deadline - jiffies;
- if (left_to_sleep <= 0)
- return -ETIMEDOUT;
+ rc = wait_event_timeout(chan->flushq,
+ !chan->flushing ||
+ xdev->error,
+ max(1L, left_to_sleep));
- rc = wait_event_interruptible_timeout(chan->flushq,
- !chan->flushing ||
- xdev->error,
- left_to_sleep);
+ if (!rc)
+ return -ETIMEDOUT;
+ } else {
+ rc = wait_event_interruptible(chan->flushq,
+ !chan->flushing || xdev->error);
+ }
- 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;
}
@@ -1332,7 +1320,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;
@@ -1626,7 +1614,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);
@@ -1696,7 +1684,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;
@@ -1833,7 +1821,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
next prev parent reply other threads:[~2026-11-17 11:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 11:58 [PATCH v2 0/8] char: xillybus: Fix issues reported by Sashiko Eli Billauer
2026-11-17 11:58 ` [PATCH v2 1/8] char: xillybus: Improve sanity check Eli Billauer
2026-11-17 11:58 ` [PATCH v2 2/8] char: xillybus: Safer access of unaligned pointers Eli Billauer
2026-11-17 11:58 ` [PATCH v2 3/8] char: xillybus: Return error in fops read method handler Eli Billauer
2026-11-17 11:58 ` [PATCH v2 4/8] char: xillybus: Rely on FMODE flags in poll method Eli Billauer
2026-11-17 11:58 ` Eli Billauer [this message]
2026-11-17 11:59 ` [PATCH v2 6/8] char: xillybus: Correct handling of wait queue Eli Billauer
2026-11-17 11:59 ` [PATCH v2 7/8] char: xillybus: Avoid indefinite sleep of work item Eli Billauer
2026-11-17 11:59 ` [PATCH v2 8/8] char: xillybus: Cancel delayed work items before teardown Eli Billauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261117115902.41359-6-eli.billauer@gmail.com \
--to=eli.billauer@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox