Skip to contentSkip to conversation

Remove Unnecessary typecast of c90 int constant

PATCH In review UMWARI JOVIAL 4 participants 5 messages Oct 28, 2022 – Oct 29, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove Unnecessary typecast of c90 int constant

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'

---
 drivers/staging/rtl8192e/rtllib_softmac_wx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_softmac_wx.c +2 -2
index fdf867a5dd7a..4fc4fb25d8d6 100644
@@ -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;
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 5 lines · UMWARI JOVIAL

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

Quoted 26 lines
---
 drivers/staging/rtl8192e/rtllib_softmac_wx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_softmac_wx.c +2 -3
index fdf867a5dd7a..4fc4fb25d8d6 100644
@@ -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

#2 lore raw

let me again look in deep into it and see why
Thank you for the comment

Quoted 48 lines · Julia Lawall
Quoted 5 lines · UMWARI JOVIAL

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

Quoted 26 lines
---
 drivers/staging/rtl8192e/rtllib_softmac_wx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192e/rtllib_softmac_wx.c +2 -3
index fdf867a5dd7a..4fc4fb25d8d6 100644
@@ -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

#3 lore raw
In reply to Julia Lawall

From: Julia Lawall

Quoted 10 lines

Sent: 28 October 2022 08:23

Quoted 5 lines · UMWARI JOVIAL

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'

Quoted 8 lines

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

Quoted 25 lines

julia

Review

Quoted 7 lines
---
 drivers/staging/rtl8192e/rtllib_softmac_wx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/staging/rtl8192e/rtllib_softmac_wx.c

Quoted 14 lines

index fdf867a5dd7a..4fc4fb25d8d6 100644

drivers/staging/rtl8192e/rtllib_softmac_wx.c +2 -2
@@ -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;
 
Quoted 5 lines
Quoted 5 lines

--
2.25.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

maintainer
#4 lore raw
In reply to Julia Lawall
Quoted 9 lines · Julia Lawall
Quoted 5 lines · UMWARI JOVIAL

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'

Quoted 8 lines

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:
---

scripts/checkpatch.pl +2 -1
index 4e187202e77a6..9958a774efaf1 100755
@@ -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 = "";