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 4/7] char: xillybus: Use unsigned arithmetic for jiffies differences
Date: Tue, 30 Jun 2026 11:23:27 +0200 [thread overview]
Message-ID: <20260630092330.43534-5-eli.billauer@gmail.com> (raw)
In-Reply-To: <20260630092330.43534-1-eli.billauer@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2026-06-30 9:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 9:23 [PATCH 0/7] char: xillybus: Harden driver and improve code quality Eli Billauer
2026-06-30 9:23 ` [PATCH 1/7] char: xillybus: Improve control of execution flow with mutexes Eli Billauer
2026-06-30 9:23 ` [PATCH 2/7] char: xillybus: Remove duplicate error path code Eli Billauer
2026-06-30 9:23 ` [PATCH 3/7] char: xillybus: Avoid possible bandwidth inefficiency Eli Billauer
2026-06-30 9:23 ` Eli Billauer [this message]
2026-06-30 9:23 ` [PATCH 5/7] char: xillybus: Integer arithmetic improvements Eli Billauer
2026-06-30 9:23 ` [PATCH 6/7] char: xillybus: Add defensive sanity checks Eli Billauer
2026-06-30 9:23 ` [PATCH 7/7] char: xillybus: Ignore and report unsolicited interrupts 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=20260630092330.43534-5-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