From: Zhen Lei Date: Fri, 25 Nov 2022 09:13:58 +0000 (+0800) Subject: get rid of INT_LIMIT, use type_max() instead X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=ea258f159da14a710f9cb88656558538b5ba5b76;p=linux.git get rid of INT_LIMIT, use type_max() instead INT_LIMIT() tries to do what type_max() does, except that type_max() doesn't rely upon undefined behaviour[*], might as well use type_max() instead. [*] if T is an N-bit signed integer type, the maximal value in T is pow(2, N - 1) - 1, all right, but naive expression for that value ends up with a couple of wraparounds and as usual for wraparounds in signed types, that's an undefined behaviour. type_max() takes care to avoid those... Caught-by: UBSAN Suggested-by: Eric Biggers Signed-off-by: Zhen Lei Reviewed-by: Eric Biggers Signed-off-by: Al Viro --- diff --git a/include/linux/fs.h b/include/linux/fs.h index e654435f16512..a384741b14494 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1131,9 +1131,8 @@ struct file_lock_context { /* The following constant reflects the upper bound of the file/locking space */ #ifndef OFFSET_MAX -#define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1))) -#define OFFSET_MAX INT_LIMIT(loff_t) -#define OFFT_OFFSET_MAX INT_LIMIT(off_t) +#define OFFSET_MAX type_max(loff_t) +#define OFFT_OFFSET_MAX type_max(off_t) #endif extern void send_sigio(struct fown_struct *fown, int fd, int band);