Skip to content

Commit 68920c9

Browse files
aryabinintorvalds
authored andcommitted
net/mac80211/debugfs.c: prevent build failure with CONFIG_UBSAN=y
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: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: "David S. Miller" <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5c9cf8a commit 68920c9

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

net/mac80211/debugfs.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static const struct file_operations reset_ops = {
9191
};
9292
#endif
9393

94-
static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = {
94+
static const char *hw_flag_names[] = {
9595
#define FLAG(F) [IEEE80211_HW_##F] = #F
9696
FLAG(HAS_RATE_CONTROL),
9797
FLAG(RX_INCLUDES_FCS),
@@ -126,9 +126,6 @@ static const char *hw_flag_names[NUM_IEEE80211_HW_FLAGS + 1] = {
126126
FLAG(SUPPORTS_AMSDU_IN_AMPDU),
127127
FLAG(BEACON_TX_STATUS),
128128
FLAG(NEEDS_UNIQUE_STA_ADDR),
129-
130-
/* keep last for the build bug below */
131-
(void *)0x1
132129
#undef FLAG
133130
};
134131

@@ -148,7 +145,7 @@ static ssize_t hwflags_read(struct file *file, char __user *user_buf,
148145
/* fail compilation if somebody adds or removes
149146
* a flag without updating the name array above
150147
*/
151-
BUILD_BUG_ON(hw_flag_names[NUM_IEEE80211_HW_FLAGS] != (void *)0x1);
148+
BUILD_BUG_ON(ARRAY_SIZE(hw_flag_names) != NUM_IEEE80211_HW_FLAGS);
152149

153150
for (i = 0; i < NUM_IEEE80211_HW_FLAGS; i++) {
154151
if (test_bit(i, local->hw.flags))

0 commit comments

Comments
 (0)