[<prev] [next>] [day] [month] [year] [list]
Message-ID: <364a2f251cab4b2fbd43c661d51fcdd5@AcuMS.aculab.com>
Date: Wed, 17 Jan 2024 22:47:16 +0000
From: David Laight <David.Laight@...LAB.COM>
To: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-ext4@...r.kernel.org" <linux-ext4@...r.kernel.org>, Arnd Bergmann
<arnd@...db.de>
CC: "Theodore Y. Ts'o" <tytso@....edu>, "'adilger.kernel@...ger.ca'"
<adilger.kernel@...ger.ca>
Subject: Subject: [PATCH next] ext4: super: Use clamp() instead of clamp_val()
to bound timestamps
Commit 6a0678a79bb3a extended the superblock timestamps to 40 bits.
The time64_t (signed 64bit) was bounded using:
now = clamp_val(now, 0, (1ull << 40) - 1);
which is equivalent to:
now = clamp(now, (typeof(now))0, (typeof(now))((1ull << 40) - 1));
However clamp_val() is an 'accident waiting to happen' because it
is very easy to specify bounds that get masked by the cast.
The current clamp() only requires the three values to have the same
signedness - not the same types.
So changing the upper limit to a signed value allows clamp() be used.
This is the only place in the kernel I build where replacing clamp_val()
with clamp() generates a compile-time error.
This is a similar 'problem' to code like:
unsigned int val = ...
u8 bounded = min_t(u8, val, 255);
which is surprisingly common and has been a real bug.
Signed-off-by: David Laight <david.laight@...lab.com>
---
fs/ext4/super.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 0980845c8b8f..714d51a1667b 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -425,7 +425,7 @@ void ext4_itable_unused_set(struct super_block *sb,
static void __ext4_update_tstamp(__le32 *lo, __u8 *hi, time64_t now)
{
- now = clamp_val(now, 0, (1ull << 40) - 1);
+ now = clamp(now, 0, (1ll << 40) - 1);
*lo = cpu_to_le32(lower_32_bits(now));
*hi = upper_32_bits(now);
--
2.17.1
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Powered by blists - more mailing lists