Subject: [PATCH next] ext4: super: Use clamp() instead of clamp_val() to bound timestamps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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)






[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux