Skip to content

Commit 56fd616

Browse files
arndbakpm00
authored andcommitted
kcov: avoid clang out-of-range warning
The area_size is never larger than the maximum on 64-bit architectutes: kernel/kcov.c:634:29: error: result of comparison of constant 1152921504606846975 with expression of type '__u32' (aka 'unsigned int') is always false [-Werror,-Wtautological-constant-out-of-range-compare] if (remote_arg->area_size > LONG_MAX / sizeof(unsigned long)) ~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The compiler can correctly optimize the check away and the code appears correct to me, so just add a cast to avoid the warning. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Arnd Bergmann <[email protected]> Reviewed-by: Justin Stitt <[email protected]> Cc: Andrey Konovalov <[email protected]> Cc: Bill Wendling <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Nathan Chancellor <[email protected]> Cc: Nick Desaulniers <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent b0f970c commit 56fd616

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/kcov.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,8 @@ static int kcov_ioctl_locked(struct kcov *kcov, unsigned int cmd,
627627
mode = kcov_get_mode(remote_arg->trace_mode);
628628
if (mode < 0)
629629
return mode;
630-
if (remote_arg->area_size > LONG_MAX / sizeof(unsigned long))
630+
if ((unsigned long)remote_arg->area_size >
631+
LONG_MAX / sizeof(unsigned long))
631632
return -EINVAL;
632633
kcov->mode = mode;
633634
t->kcov = kcov;

0 commit comments

Comments
 (0)