staging: wimax/i2400m: don't change the endianness of one byte variable
PATCH 1/1 staging: wimax/i2400m: don't change the endianness of one byte variable
It is wrong to change the endianness of a variable which has just one byte size.
Sparse warnings fixed:
drivers/staging//wimax/i2400m/control.c:452:17: warning: cast to restricted __le32 drivers/staging//wimax/i2400m/control.c:452:17: warning: cast to restricted __le32 drivers/staging//wimax/i2400m/op-rfkill.c:159:14: warning: cast to restricted __le32 drivers/staging//wimax/i2400m/op-rfkill.c:160:14: warning: cast to restricted __le32
--- drivers/staging/wimax/i2400m/control.c | 4 ++-- drivers/staging/wimax/i2400m/op-rfkill.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/wimax/i2400m/control.c +2 -2
@@ -452,8 +452,8 @@ void i2400m_report_state_parse_tlv(struct i2400m *i2400m,d_printf (2 , dev,"%s: RF status TLV " "found (0x%04x), sw 0x%02x hw 0x%02x\n" , tag,I2400M_TLV_RF_STATUS , -le32_to_cpu (rfss->sw_rf_switch), -le32_to_cpu (rfss->hw_rf_switch)); + rfss->sw_rf_switch, + rfss->hw_rf_switch);i2400m_report_tlv_rf_switches_status (i2400m, rfss); }if (0 ==i2400m_tlv_match (tlv,I2400M_TLV_MEDIA_STATUS ,sizeof (*ms))) {
drivers/staging/wimax/i2400m/op-rfkill.c +2 -2
@@ -156,8 +156,8 @@ void i2400m_report_tlv_rf_switches_status(enum i2400m_rf_switch_status hw, sw;enum wimax_st wimax_state; - sw =le32_to_cpu (rfss->sw_rf_switch); - hw =le32_to_cpu (rfss->hw_rf_switch); + sw = rfss->sw_rf_switch; + hw = rfss->hw_rf_switch;d_fnstart (3 , dev,"(i2400m %p rfss %p [hw %u sw %u])\n" , i2400m, rfss, hw, sw);
Signature · 1 line
2.25.1
Quoted 16 lines · Greg KH
Quoted 15 lines · Muhammad Usama Anjum
It is wrong to change the endianness of a variable which has just one byte size.
Sparse warnings fixed:
drivers/staging//wimax/i2400m/control.c:452:17: warning: cast to restricted__le32drivers/staging//wimax/i2400m/control.c:452:17: warning: cast to restricted__le32drivers/staging//wimax/i2400m/op-rfkill.c:159:14: warning: cast to restricted__le32drivers/staging//wimax/i2400m/op-rfkill.c:160:14: warning: cast to restricted__le32Signed-off-by Muhammad Usama Anjum <[email protected]>--- drivers/staging/wimax/i2400m/control.c | 4 ++-- drivers/staging/wimax/i2400m/op-rfkill.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 15 lines
drivers/staging/wimax/i2400m/control.c void i2400m_report_state_parse_tlv(struct i2400m *i2400m, · line 456
Quoted 12 lines
drivers/staging/wimax/i2400m/control.c +2
-2@@ -452,8 +452,8 @@ void i2400m_report_state_parse_tlv(struct i2400m *i2400m,d_printf (2 , dev,"%s: RF status TLV " "found (0x%04x), sw 0x%02x hw 0x%02x\n" , tag,I2400M_TLV_RF_STATUS , -le32_to_cpu (rfss->sw_rf_switch), -le32_to_cpu (rfss->hw_rf_switch)); + rfss->sw_rf_switch, + rfss->hw_rf_switch);What do you mean by "one byte"? This is a le32 sized variable, right? If not, why isn't the
le32_to_cpu()call complaining?
These two variables are of type _u8, one byte.
__u8 sw_rf_switch; __u8 hw_rf_switch;
They aren't of type __le32. le32_to_cpu() macro should have complained. But it isn't complaining. It seems like whatever we pass to this macro, it casts it to __le32 forcefully (it seems like wrong). So we'll never get any complain from this macro directly. But we are getting complain from the sparse.
For big endian:
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x)) For little endian:
#define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
Quoted 11 lines
Quoted 11 lines
drivers/staging/wimax/i2400m/control.c +0
-0i2400m_report_tlv_rf_switches_status (i2400m, rfss); }if (0 ==i2400m_tlv_match (tlv,I2400M_TLV_MEDIA_STATUS ,sizeof (*ms))) {drivers/staging/wimax/i2400m/op-rfkill.c +0
-0@@ -156,8 +156,8 @@ void i2400m_report_tlv_rf_switches_status(enum i2400m_rf_switch_status hw, sw;enum wimax_st wimax_state;
Quoted 6 lines
drivers/staging/wimax/i2400m/op-rfkill.c void i2400m_report_tlv_rf_switches_status( · line 160
Quoted 4 lines
drivers/staging/wimax/i2400m/op-rfkill.c +2
-2- sw =le32_to_cpu (rfss->sw_rf_switch); - hw =le32_to_cpu (rfss->hw_rf_switch); + sw = rfss->sw_rf_switch; + hw = rfss->hw_rf_switch;Same here.
Same here.
Quoted 3 lines
thanks,
greg k-h
Greg KH
maintainerQuoted 20 lines · Muhammad Usama Anjum
It is wrong to change the endianness of a variable which has just one byte size.
Sparse warnings fixed:
drivers/staging//wimax/i2400m/control.c:452:17: warning: cast to restricted__le32drivers/staging//wimax/i2400m/control.c:452:17: warning: cast to restricted__le32drivers/staging//wimax/i2400m/op-rfkill.c:159:14: warning: cast to restricted__le32drivers/staging//wimax/i2400m/op-rfkill.c:160:14: warning: cast to restricted__le32Signed-off-by Muhammad Usama Anjum <[email protected]>--- drivers/staging/wimax/i2400m/control.c | 4 ++-- drivers/staging/wimax/i2400m/op-rfkill.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)drivers/staging/wimax/i2400m/control.c +0
-0
drivers/staging/wimax/i2400m/control.c void i2400m_report_state_parse_tlv(struct i2400m *i2400m, · line 456
Quoted 7 lines
drivers/staging/wimax/i2400m/control.c +2
-2@@ -452,8 +452,8 @@ void i2400m_report_state_parse_tlv(struct i2400m *i2400m,d_printf (2 , dev,"%s: RF status TLV " "found (0x%04x), sw 0x%02x hw 0x%02x\n" , tag,I2400M_TLV_RF_STATUS , -le32_to_cpu (rfss->sw_rf_switch), -le32_to_cpu (rfss->hw_rf_switch)); + rfss->sw_rf_switch, + rfss->hw_rf_switch);
What do you mean by "one byte"? This is a le32 sized variable, right? If not, why isn't the le32_to_cpu() call complaining?
Quoted 8 lines
drivers/staging/wimax/i2400m/control.c +0
-0i2400m_report_tlv_rf_switches_status (i2400m, rfss); }if (0 ==i2400m_tlv_match (tlv,I2400M_TLV_MEDIA_STATUS ,sizeof (*ms))) {drivers/staging/wimax/i2400m/op-rfkill.c +0
-0
drivers/staging/wimax/i2400m/op-rfkill.c void i2400m_report_tlv_rf_switches_status( · line 160
Quoted 7 lines
drivers/staging/wimax/i2400m/op-rfkill.c +2
-2@@ -156,8 +156,8 @@ void i2400m_report_tlv_rf_switches_status(enum i2400m_rf_switch_status hw, sw;enum wimax_st wimax_state; - sw =le32_to_cpu (rfss->sw_rf_switch); - hw =le32_to_cpu (rfss->hw_rf_switch); + sw = rfss->sw_rf_switch; + hw = rfss->hw_rf_switch;
Same here.
thanks,
greg k-h
Quoted 43 lines · Muhammad Usama Anjum
Quoted 16 lines · Greg KH
Quoted 15 lines · Muhammad Usama Anjum
It is wrong to change the endianness of a variable which has just one byte size.
Sparse warnings fixed:
drivers/staging//wimax/i2400m/control.c:452:17: warning: cast to restricted__le32drivers/staging//wimax/i2400m/control.c:452:17: warning: cast to restricted__le32drivers/staging//wimax/i2400m/op-rfkill.c:159:14: warning: cast to restricted__le32drivers/staging//wimax/i2400m/op-rfkill.c:160:14: warning: cast to restricted__le32Signed-off-by Muhammad Usama Anjum <[email protected]>--- drivers/staging/wimax/i2400m/control.c | 4 ++-- drivers/staging/wimax/i2400m/op-rfkill.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)Quoted 15 lines
drivers/staging/wimax/i2400m/control.c void i2400m_report_state_parse_tlv(struct i2400m *i2400m, · line 456
Quoted 12 lines
drivers/staging/wimax/i2400m/control.c +2
-2@@ -452,8 +452,8 @@ void i2400m_report_state_parse_tlv(struct i2400m *i2400m,d_printf (2 , dev,"%s: RF status TLV " "found (0x%04x), sw 0x%02x hw 0x%02x\n" , tag,I2400M_TLV_RF_STATUS , -le32_to_cpu (rfss->sw_rf_switch), -le32_to_cpu (rfss->hw_rf_switch)); + rfss->sw_rf_switch, + rfss->hw_rf_switch);What do you mean by "one byte"? This is a le32 sized variable, right? If not, why isn't the
le32_to_cpu()call complaining?These two variables are of type
_u8, one byte.__u8 sw_rf_switch; __u8 hw_rf_switch;They aren't of type
__le32.le32_to_cpu()macro should have complained. But it isn't complaining. It seems like whatever we pass to this macro, it casts it to__le32forcefully (it seems like wrong). So we'll never get any complain from this macro directly. But we are getting complain from the sparse.
Quoted 4 lines
For big endian:
#define__le32_to_cpu(x)__swab32((__force __u32)(__le32)(x))For little endian:
#define__le32_to_cpu(x)((__force__u32)(__le32)(x))
Right, it seems this driver has been broken on big-endian ever since it was first merged in 2008.
Arnd