* Re: [PATCH] Remove Unnecessary typecast of c90 int constant
2022-10-28 7:22 ` Julia Lawall
@ 2022-10-28 7:42 ` jovial umwari
2022-10-29 11:15 ` David Laight
2022-10-29 14:38 ` Joe Perches
2 siblings, 0 replies; 5+ messages in thread
From: jovial umwari @ 2022-10-28 7:42 UTC (permalink / raw)
To: Julia Lawall; +Cc: gregkh, linux-staging, linux-kernel, outreachy
let me again look in deep into it and see why
Thank you for the comment
On Fri, 28 Oct 2022 at 10:22, Julia Lawall <julia.lawall@inria.fr> 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.
>
> julia
>
> >
> > Signed-off-by: UMWARI JOVIAL <umwarijovial@gmail.com>
> > ---
> > drivers/staging/rtl8192e/rtllib_softmac_wx.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8192e/rtllib_softmac_wx.c b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> > index fdf867a5dd7a..4fc4fb25d8d6 100644
> > --- a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> > +++ b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> > @@ -41,8 +41,8 @@ int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a,
> >
> > /* if setting by freq convert to channel */
> > if (fwrq->e == 1) {
> > - if ((fwrq->m >= (int)2.412e8 &&
> > - fwrq->m <= (int)2.487e8)) {
> > + if ((fwrq->m >= 2.412e8 &&
> > + fwrq->m <= 2.487e8)) {
> > int f = fwrq->m / 100000;
> > int c = 0;
> >
> > --
> > 2.25.1
> >
> >
> >
^ permalink raw reply [flat|nested] 5+ messages in thread* RE: [PATCH] Remove Unnecessary typecast of c90 int constant
2022-10-28 7:22 ` Julia Lawall
2022-10-28 7:42 ` jovial umwari
@ 2022-10-29 11:15 ` David Laight
2022-10-29 14:38 ` Joe Perches
2 siblings, 0 replies; 5+ messages in thread
From: David Laight @ 2022-10-29 11:15 UTC (permalink / raw)
To: 'Julia Lawall', UMWARI JOVIAL
Cc: gregkh@linuxfoundation.org, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org, outreachy@lists.linux.dev
From: Julia Lawall
> Sent: 28 October 2022 08:23
>
> 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.
Much better to just use 241200000u (or 241200u * 1000 for readability).
David
>
> julia
>
> >
> > Signed-off-by: UMWARI JOVIAL <umwarijovial@gmail.com>
> > ---
> > drivers/staging/rtl8192e/rtllib_softmac_wx.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> > index fdf867a5dd7a..4fc4fb25d8d6 100644
> > --- a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> > +++ b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> > @@ -41,8 +41,8 @@ int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a,
> >
> > /* if setting by freq convert to channel */
> > if (fwrq->e == 1) {
> > - if ((fwrq->m >= (int)2.412e8 &&
> > - fwrq->m <= (int)2.487e8)) {
> > + if ((fwrq->m >= 2.412e8 &&
> > + fwrq->m <= 2.487e8)) {
> > int f = fwrq->m / 100000;
> > int c = 0;
> >
> > --
> > 2.25.1
> >
> >
> >
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] Remove Unnecessary typecast of c90 int constant
2022-10-28 7:22 ` Julia Lawall
2022-10-28 7:42 ` jovial umwari
2022-10-29 11:15 ` David Laight
@ 2022-10-29 14:38 ` Joe Perches
2 siblings, 0 replies; 5+ messages in thread
From: Joe Perches @ 2022-10-29 14:38 UTC (permalink / raw)
To: Julia Lawall, UMWARI JOVIAL
Cc: gregkh, linux-staging, linux-kernel, outreachy
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 = "";
^ permalink raw reply related [flat|nested] 5+ messages in thread