* [PATCH] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value
@ 2017-06-25 14:40 Guillermo O. Freschi
2017-06-26 10:27 ` kbuild test robot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Guillermo O. Freschi @ 2017-06-25 14:40 UTC (permalink / raw)
To: Aditya Shankar, Ganesh Krishna, linux-wireless; +Cc: Guillermo O. Freschi
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.
Signed-off-by: Guillermo O. Freschi <kedrot@gmail.com>
---
drivers/staging/wilc1000/host_interface.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index f7c22d7b28d1..ed614698c22c 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -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);
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value
2017-06-25 14:40 [PATCH] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value Guillermo O. Freschi
@ 2017-06-26 10:27 ` kbuild test robot
2017-06-26 11:29 ` [PATCH v2] " Guillermo O. Freschi
2017-06-26 11:47 ` Guillermo O. Freschi
2 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2017-06-26 10:27 UTC (permalink / raw)
To: Guillermo O. Freschi
Cc: kbuild-all, Aditya Shankar, Ganesh Krishna, linux-wireless,
Guillermo O. Freschi
[-- Attachment #1: Type: text/plain, Size: 2134 bytes --]
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
[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 28132 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value
2017-06-25 14:40 [PATCH] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value Guillermo O. Freschi
2017-06-26 10:27 ` kbuild test robot
@ 2017-06-26 11:29 ` Guillermo O. Freschi
2017-06-26 11:47 ` Guillermo O. Freschi
2 siblings, 0 replies; 4+ messages in thread
From: Guillermo O. Freschi @ 2017-06-26 11:29 UTC (permalink / raw)
To: Aditya Shankar, Ganesh Krishna, linux-wireless; +Cc: Guillermo O. Freschi
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.
Signed-off-by: Guillermo O. Freschi <kedrot@gmail.com>
---
drivers/staging/wilc1000/host_interface.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index f7c22d7b28d1..ed614698c22c 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -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);
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value
2017-06-25 14:40 [PATCH] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value Guillermo O. Freschi
2017-06-26 10:27 ` kbuild test robot
2017-06-26 11:29 ` [PATCH v2] " Guillermo O. Freschi
@ 2017-06-26 11:47 ` Guillermo O. Freschi
2 siblings, 0 replies; 4+ messages in thread
From: Guillermo O. Freschi @ 2017-06-26 11:47 UTC (permalink / raw)
To: Aditya Shankar, Ganesh Krishna, linux-wireless; +Cc: Guillermo O. Freschi
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.
Signed-off-by: Guillermo O. Freschi <kedrot@gmail.com>
---
drivers/staging/wilc1000/host_interface.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c
index f7c22d7b28d1..4591b1452df4 100644
--- a/drivers/staging/wilc1000/host_interface.c
+++ b/drivers/staging/wilc1000/host_interface.c
@@ -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);
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-06-26 11:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-25 14:40 [PATCH] drivers: staging: wilc1000/host_interface.c Fix sparse warning: right shift by bigger than source value Guillermo O. Freschi
2017-06-26 10:27 ` kbuild test robot
2017-06-26 11:29 ` [PATCH v2] " Guillermo O. Freschi
2017-06-26 11:47 ` Guillermo O. Freschi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.