From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49A14431A5E for ; Wed, 5 Aug 2026 11:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785928444; cv=none; b=NWlvKSP7kCfWbAXFLWYvao0xwXc9/zhEbvCpTRmLoipp/yXTtskhrG+yvE68RggzYj18uesKeGAy3G+3hErJz9NEtcXP+X62Ld+iOHJOWZv89MvkfXNSVrQzp2p7GU+C4UoJimX2RsoEnyNlm53LfIYdrnARljNW8l06r3D2IiY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785928444; c=relaxed/simple; bh=fvA09/4M9aVhIsgwPN2BcMGW7Yvhsb2LJ1CEzSvNYBU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=l1XkofCYUptM5ew8eE7uVIa+WREixvgXeOZoLsh2Oo3BkWL85BoqQKnbEaFrKb3Gt0Xs231gXlrBOsZmeKF6CStDOYtQtiy0XIe6b7EZbbVTBSuuKyFr/+vyA3ngn8GIXWN1/g0LObPSnjn3Nzk5Sdz94mua0d15Vqw3g+c4zR4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=p3R1ihGB; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="p3R1ihGB" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-c2020421077so141540066b.3 for ; Wed, 05 Aug 2026 04:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785928440; x=1786533240; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=Jm+SRxrMh30+bn/DMDP4idMw1iL/4HQY9jA5t5ETxA4=; b=p3R1ihGBCvDESqLwWEzrqGEXX8ki/5WCURFEzIY4QTIV6I24Uew0FgZakLTKOwI1yo 9azCuahxpL4zbeouR5EMd1lc8cXjRTF/dFslTSNuWywFOsrzqHqpcM+fOuPftzhbLEyl XRj4y9hS4EMWXTgbfQWnw8DxOYeTHIpU3HRqVO/GCBVddHg0vUrrBvaD0FpLa+JAYolC 7RMESPvVYEJZU4W2kj+dGgEVqQcyLUr+SjObZyyKIATepMpOz59QTDw+4vMXczsFOymL rQftBn9htO9pz8Mh6G1Q634ABWCyXSChwCwu6Wo0BuGRbZ8/V2Ez6ygvfnJkAZ3tdwtx V8+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785928440; x=1786533240; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Jm+SRxrMh30+bn/DMDP4idMw1iL/4HQY9jA5t5ETxA4=; b=LAYISCnX6RSQNRSbLeWYBTGxr9YUSkzzFI3KEUWYfW9+EAPAwndik8PxLYJkQC6YqD riYjuxr1ku93qekquroFmB00aWJ2nYELYUQBk9DoIlx63WXBC/iEqzWkXRvX4O0YGiyl xso8Qo7S2UvUmD/oWaH4oD0H/YO12Ri5b1IaIaOHzd/3/Evpzf9kCjtBWWuHVZaDM7JX cMhdnX1a5s2ksfeG7OtF5HOENJrMTEMtbOSVNB14OwSQ0fZVAD6kGD1b0+ypWLyfuzdg ul0Xv+Ub0AvmXTsCIE57yVs2IuEF8+zzMmpMgck/TkjOFA31xPmNMAPMZtszIhq7nBoa tHVQ== X-Forwarded-Encrypted: i=1; AHgh+Rq2MGupO3/wBAIXmL21ZQ/C3BXVShhEZHqMRIIxj7/46hj6jaWI58cAhJEt0wjc3zPERmViBM6ER68F6kc=@vger.kernel.org X-Gm-Message-State: AOJu0YzSbrfoI9GDMDbCoPOcBVMLuT1qlW0z4HENSaaomprCLFNq1+sY yveEbYgTXR7czmYnbN2SS3guHBZSWjRjpNwS8TZafle0HtIwper1uTzi X-Gm-Gg: AR+sD10jpWOywlskFsJuW0WI3esMCv9WKaH+4cfESIggaXER7X7vZZd9RmofZRjwuYk O3dYrKIWfifnREGzPG+6IRzqGN6ahYW8f6tNDGDSv4uYpUP4r4ID9i95mZb9CMjVRqcK7skvqAd aEZf6v1jPS1mKcPixx2lH/Bx/+foYdEdDiAVCry1PvYc9hymJ+XdHxVm9EJcG56UfoisUTA+ipf MhdnsHvjw3ov4pX07QF4qfYrxiDxRJtnceHKjIQWvK/LDNpoADhnjFHl2iKcWLYPEwzsRE8kEvd JXmXV8Hxlf2bIz7xYND20eL7mC9df4pwx6jw9vi+hm+FB8ibFzKUNyEGzxDJiLyguHEmA7epZUY 8fwlaL5Idv1YacTLQl/amT5V8WAjVnBZSfv9bgaT99cZp8mIvWVqTehzMB/FjxvbNerIpx1F1Vl vf3xQNqW4xGaCnFmNr7UHoWphCWBQ13Feqa8RXOUi3zNskdg39ErIjGmJD8NrruZttmrrP9S5m7 3AwsXvrKXPspvyk X-Received: by 2002:a17:907:724f:b0:c1c:4afd:8d8c with SMTP id a640c23a62f3a-c2039b5ae10mr272800966b.14.1785928440160; Wed, 05 Aug 2026 04:14:00 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c2036225b96sm97735366b.12.2026.08.05.04.13.59 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Aug 2026 04:13:59 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, corbet@lwn.net, Eli Billauer Subject: [PATCH v5 4/7] char: xillybus: Use unsigned arithmetic for jiffies differences Date: Wed, 5 Aug 2026 13:13:34 +0200 Message-Id: <20260805111337.69178-5-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260805111337.69178-1-eli.billauer@gmail.com> References: <20260805111337.69178-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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. Assisted-by: Deepseek:v4-pro Kimi:K2.6 ChatGPT:GPT-5.5 Claude:Sonnet-4.6 Signed-off-by: Eli Billauer --- Notes: Changelog: ========= No change on v4->v5. No change on v3->v4. Changes v2->v3: -- Add Assisted-by tag to description No change on v1->v2. 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 ef5b1816b277..e2270a64b659 100644 --- a/drivers/char/xillybus/xillyusb.c +++ b/drivers/char/xillybus/xillyusb.c @@ -1132,12 +1132,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) @@ -1146,7 +1147,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, @@ -1157,7 +1159,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); @@ -1207,7 +1209,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; @@ -1440,7 +1442,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; @@ -1469,7 +1472,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