[PATCH 4/7] char: xillybus: Use unsigned arithmetic for jiffies differences
From: Eli Billauer
Date: Tue Jun 30 2026 - 05:29:15 EST
Change the type of jiffies-related deadline variables from long to
unsigned long, and remove unnecessary casts when computing time
remaining as deadline - jiffies.
No functional change is expected: although signed overflow is undefined
in the C standard, processors perform the calculation correctly in
practice. Using unsigned arithmetic is nevertheless the proper way to
handle jiffies differences.
Signed-off-by: Eli Billauer <eli.billauer@xxxxxxxxx>
---
drivers/char/xillybus/xillybus_core.c | 5 +++--
drivers/char/xillybus/xillyusb.c | 17 ++++++++++-------
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/drivers/char/xillybus/xillybus_core.c b/drivers/char/xillybus/xillybus_core.c
index 952ef149aba1..7acebc1e6050 100644
--- a/drivers/char/xillybus/xillybus_core.c
+++ b/drivers/char/xillybus/xillybus_core.c
@@ -694,7 +694,8 @@ static ssize_t xillybus_read(struct file *filp, char __user *userbuf,
unsigned long flags;
int bytes_done = 0;
int no_time_left = 0;
- long deadline, left_to_sleep;
+ unsigned long deadline;
+ long left_to_sleep;
struct xilly_channel *channel = filp->private_data;
int empty, reached_eof, exhausted, ready;
@@ -938,7 +939,7 @@ static ssize_t xillybus_read(struct file *filp, char __user *userbuf,
return -EINTR;
}
- left_to_sleep = deadline - ((long) jiffies);
+ left_to_sleep = deadline - jiffies;
/*
* If our time is out, skip the waiting. We may miss wr_sleepy
diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c
index 7d2434c02fa7..aa08206a18ef 100644
--- a/drivers/char/xillybus/xillyusb.c
+++ b/drivers/char/xillybus/xillyusb.c
@@ -1127,12 +1127,13 @@ static int xillyusb_send_opcode(struct xillyusb_dev *xdev,
*/
static int flush_downstream(struct xillyusb_channel *chan,
- long timeout,
+ unsigned long timeout,
bool interruptible)
{
struct xillyusb_dev *xdev = chan->xdev;
int chan_num = chan->chan_idx << 1;
- long deadline, left_to_sleep;
+ unsigned long deadline;
+ long left_to_sleep;
int rc;
if (chan->flushed)
@@ -1141,7 +1142,8 @@ static int flush_downstream(struct xillyusb_channel *chan,
deadline = jiffies + 1 + timeout;
if (chan->flushing) {
- long cancel_deadline = jiffies + 1 + XILLY_RESPONSE_TIMEOUT;
+ unsigned long cancel_deadline =
+ jiffies + 1 + XILLY_RESPONSE_TIMEOUT;
chan->canceled = 0;
rc = xillyusb_send_opcode(xdev, chan_num,
@@ -1152,7 +1154,7 @@ static int flush_downstream(struct xillyusb_channel *chan,
/* Ignoring interrupts. Cancellation must be handled */
while (!chan->canceled) {
- left_to_sleep = cancel_deadline - ((long)jiffies);
+ left_to_sleep = cancel_deadline - jiffies;
if (left_to_sleep <= 0) {
report_io_error(xdev, -EIO);
@@ -1202,7 +1204,7 @@ static int flush_downstream(struct xillyusb_channel *chan,
}
while (chan->flushing) {
- left_to_sleep = deadline - ((long)jiffies);
+ left_to_sleep = deadline - jiffies;
if (left_to_sleep <= 0)
return -ETIMEDOUT;
@@ -1435,7 +1437,8 @@ static ssize_t xillyusb_read(struct file *filp, char __user *userbuf,
struct xillyfifo *fifo = chan->in_fifo;
int chan_num = (chan->chan_idx << 1) | 1;
- long deadline, left_to_sleep;
+ unsigned long deadline;
+ long left_to_sleep;
int bytes_done = 0;
bool sent_set_push = false;
int rc;
@@ -1464,7 +1467,7 @@ static ssize_t xillyusb_read(struct file *filp, char __user *userbuf,
bytes_done += rc;
chan->in_consumed_bytes += rc;
- left_to_sleep = deadline - ((long)jiffies);
+ left_to_sleep = deadline - jiffies;
/*
* Some 32-bit arithmetic that may wrap. Note that
--
2.34.1