drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value
PATCH 1/1 drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value
Shifting by equal to or bigger than the width of a type results in undefined behavior. By using a wide enough temporary variable the issue can be avoided.
--- drivers/staging/wilc1000/host_interface.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/staging/wilc1000/host_interface.c +6 -4
@@ -2416,10 +2416,12 @@ static void Handle_SetMulticastFilter(struct wilc_vif *vif, goto ERRORHANDLER; pu8CurrByte = wid.val; - *pu8CurrByte++ = (strHostIfSetMulti->enabled &0xFF ); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >>8 ) &0xFF ); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >>16 ) &0xFF ); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >>24 ) &0xFF ); + +u32 enabled = strHostIfSetMulti->enabled; + *pu8CurrByte++ = (enabled &0xFF ); + *pu8CurrByte++ = ((enabled >>8 ) &0xFF ); + *pu8CurrByte++ = ((enabled >>16 ) &0xFF ); + *pu8CurrByte++ = ((enabled >>24 ) &0xFF ); *pu8CurrByte++ = (strHostIfSetMulti->cnt &0xFF ); *pu8CurrByte++ = ((strHostIfSetMulti->cnt >>8 ) &0xFF );
Signature · 1 line
2.11.0
kbuild test robot
build boturl: https://github.com/0day-ci/linux/commits/Guillermo-O-Freschi/drivers-staging-wilc1000-host_interface-c-Fix-sparse-warning-right-shift-by-bigger-than-source-value/20170626-173132 config…
Hi Guillermo,
[auto build test WARNING on staging/staging-testing]
[also build test WARNING on next-20170626]
[cannot apply to v4.12-rc7]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Guillermo-O-Freschi/drivers-staging-wilc1000-host_interface-c-Fix-sparse-warning-right-shift-by-bigger-than-source-value/20170626-173132
config: x86_64-randconfig-x007-201726 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 All warnings (new ones prefixed by >>):
drivers/staging/wilc1000/host_interface.c: In function 'Handle_SetMulticastFilter':
>> drivers/staging/wilc1000/host_interface.c:2420:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
u32 enabled = strHostIfSetMulti->enabled;
^~~vim +2420 drivers/staging/wilc1000/host_interface.c
2404 static void Handle_SetMulticastFilter(struct wilc_vif *vif,
2405 struct set_multicast *strHostIfSetMulti)
2406 {
2407 s32 result = 0;
2408 struct wid wid;
2409 u8 *pu8CurrByte;
2410
2411 wid.id = (u16)WID_SETUP_MULTICAST_FILTER;
2412 wid.type = WID_BIN;
2413 wid.size = sizeof(struct set_multicast) + ((strHostIfSetMulti->cnt) * ETH_ALEN);
2414 wid.val = kmalloc(wid.size, GFP_KERNEL);
2415 if (!wid.val)
2416 goto ERRORHANDLER;
2417
2418 pu8CurrByte = wid.val;
2419
> 2420 u32 enabled = strHostIfSetMulti->enabled;
2421 *pu8CurrByte++ = (enabled & 0xFF);
2422 *pu8CurrByte++ = ((enabled >> 8) & 0xFF);
2423 *pu8CurrByte++ = ((enabled >> 16) & 0xFF);
2424 *pu8CurrByte++ = ((enabled >> 24) & 0xFF);
2425
2426 *pu8CurrByte++ = (strHostIfSetMulti->cnt & 0xFF);
2427 *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 8) & 0xFF);
2428 *pu8CurrByte++ = ((strHostIfSetMulti->cnt >> 16) & 0xFF);
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v2 1/1 drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value
In reply to Guillermo O. FreschiShifting by equal to or bigger than the width of a type results in undefined behavior. By using a wide enough temporary variable the issue can be avoided.
--- drivers/staging/wilc1000/host_interface.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/staging/wilc1000/host_interface.c +6 -4
@@ -2416,10 +2416,12 @@ static void Handle_SetMulticastFilter(struct wilc_vif *vif, goto ERRORHANDLER; pu8CurrByte = wid.val; - *pu8CurrByte++ = (strHostIfSetMulti->enabled &0xFF ); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >>8 ) &0xFF ); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >>16 ) &0xFF ); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >>24 ) &0xFF ); + +u32 enabled = strHostIfSetMulti->enabled; + *pu8CurrByte++ = (enabled &0xFF ); + *pu8CurrByte++ = ((enabled >>8 ) &0xFF ); + *pu8CurrByte++ = ((enabled >>16 ) &0xFF ); + *pu8CurrByte++ = ((enabled >>24 ) &0xFF ); *pu8CurrByte++ = (strHostIfSetMulti->cnt &0xFF ); *pu8CurrByte++ = ((strHostIfSetMulti->cnt >>8 ) &0xFF );
Signature · 1 line
2.11.0
PATCH v2 1/1 drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value
In reply to Guillermo O. FreschiShifting by equal to or bigger than the width of a type results in undefined behavior. By using a wide enough temporary variable the issue can be avoided.
--- drivers/staging/wilc1000/host_interface.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/staging/wilc1000/host_interface.c +7 -4
@@ -2407,6 +2407,7 @@ static void Handle_SetMulticastFilter(struct wilc_vif *vif,s32 result =0 ;struct wid wid;u8 *pu8CurrByte; +u32 enabled; wid.id = (u16 )WID_SETUP_MULTICAST_FILTER ; wid.type =WID_BIN ;
@@ -2416,10 +2417,12 @@ static void Handle_SetMulticastFilter(struct wilc_vif *vif, goto ERRORHANDLER; pu8CurrByte = wid.val; - *pu8CurrByte++ = (strHostIfSetMulti->enabled &0xFF ); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >>8 ) &0xFF ); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >>16 ) &0xFF ); - *pu8CurrByte++ = ((strHostIfSetMulti->enabled >>24 ) &0xFF ); + + enabled = strHostIfSetMulti->enabled; + *pu8CurrByte++ = (enabled &0xFF ); + *pu8CurrByte++ = ((enabled >>8 ) &0xFF ); + *pu8CurrByte++ = ((enabled >>16 ) &0xFF ); + *pu8CurrByte++ = ((enabled >>24 ) &0xFF ); *pu8CurrByte++ = (strHostIfSetMulti->cnt &0xFF ); *pu8CurrByte++ = ((strHostIfSetMulti->cnt >>8 ) &0xFF );
Signature · 1 line
2.11.0