Re: [PATCH] Remove Unnecessary typecast of c90 int constant
From: Joe Perches
Date: Sat Oct 29 2022 - 10:38:31 EST
On Fri, 2022-10-28 at 09:22 +0200, Julia Lawall wrote:
>
> On Fri, 28 Oct 2022, UMWARI JOVIAL wrote:
>
> > According to Linux kernel coding style.
> >
> > Reported by checkpatch:
> > WARNING: Unnecessary typecast of c90 int constant - '(int)2.412e8' could be '2.412e8'
> > WARNING: Unnecessary typecast of c90 int constant - '(int)2.487e8' could be '2.487e8'
>
> It's not ideal to just include the checkpatch messges verbatim in your log
> message. It woudl be better to say what you are doing and why, in
> complete sentences ("According to the Linux coding style" is not a
> complete sentence).
>
> I also suspect that the checkpatch message is wrong. Floating point
> numbers cannot be used in the kernel, and the case of the constant ensures
> that the value will be converted to an integer at compile time.
Yes, it's a checkpatch defect.
checkpatch should have this:
---
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4e187202e77a6..9958a774efaf1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6758,7 +6759,8 @@ sub process {
}
# check for cast of C90 native int or longer types constants
- if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) {
+ if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/ &&
+ $2 !~ /^$Float$/) {
my $cast = $1;
my $const = $2;
my $suffix = "";