Commit 83225c58 authored by Andrey Ryabinin's avatar Andrey Ryabinin Committed by Kleber Sacilotto de Souza

net/mac80211/debugfs.c: prevent build failure with CONFIG_UBSAN=y

BugLink: http://bugs.launchpad.net/bugs/1745266

commit 68920c97 upstream.

With upcoming CONFIG_UBSAN the following BUILD_BUG_ON in
net/mac80211/debugfs.c starts to trigger:

  BUILD_BUG_ON(hw_flag_names[NUM_IEEE80211_HW_FLAGS] != (void *)0x1);

It seems, that compiler instrumentation causes some code
deoptimizations.  Because of that GCC is not being able to resolve
condition in BUILD_BUG_ON() at compile time.

We could make size of hw_flag_names array unspecified and replace the
condition in BUILD_BUG_ON() with following:

  ARRAY_SIZE(hw_flag_names) != NUM_IEEE80211_HW_FLAGS

That will have the same effect as before (adding new flag without
updating array will trigger build failure) except it doesn't fail with
CONFIG_UBSAN.  As a bonus this patch slightly decreases size of
hw_flag_names array.
Signed-off-by: default avatarAndrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
[Daniel: backport to 4.4.]
Signed-off-by: default avatarDaniel Wagner <daniel.wagner@siemens.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent 3cdf3d19
...@@ -91,7 +91,7 @@ static const struct file_operations reset_ops = { ...@@ -91,7 +91,7 @@ static const struct file_operations reset_ops = {
}; };
#endif #endif
static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = { static const char *hw_flag_names[] = {
#define FLAG(F) [IEEE80211_HW_##F] = #F #define FLAG(F) [IEEE80211_HW_##F] = #F
FLAG(HAS_RATE_CONTROL), FLAG(HAS_RATE_CONTROL),
FLAG(RX_INCLUDES_FCS), FLAG(RX_INCLUDES_FCS),
...@@ -125,9 +125,6 @@ static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = { ...@@ -125,9 +125,6 @@ static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = {
FLAG(TDLS_WIDER_BW), FLAG(TDLS_WIDER_BW),
FLAG(SUPPORTS_AMSDU_IN_AMPDU), FLAG(SUPPORTS_AMSDU_IN_AMPDU),
FLAG(BEACON_TX_STATUS), FLAG(BEACON_TX_STATUS),
/* keep last for the build bug below */
(void *)0x1
#undef FLAG #undef FLAG
}; };
...@@ -147,7 +144,7 @@ static ssize_t hwflags_read(struct file *file, char __user *user_buf, ...@@ -147,7 +144,7 @@ static ssize_t hwflags_read(struct file *file, char __user *user_buf,
/* fail compilation if somebody adds or removes /* fail compilation if somebody adds or removes
* a flag without updating the name array above * a flag without updating the name array above
*/ */
BUILD_BUG_ON(hw_flag_names[NUM_IEEE80211_HW_FLAGS] != (void *)0x1); BUILD_BUG_ON(ARRAY_SIZE(hw_flag_names) != NUM_IEEE80211_HW_FLAGS);
for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) { for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
if (test_bit(i, local->hw.flags)) if (test_bit(i, local->hw.flags))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment