The current codebase makes use of the zero-length array language extension to the C90 standard, but the preferred mechanism to declare variable-length types such as these ones is a flexible array member[1][2], introduced in C99: struct foo { int stuff; struct boo array[]; }; By making use of the mechanism above, we will get a compiler warning in case the flexible array does not occur last in the structure, which will help us prevent some kind of undefined behavior bugs from being inadvertently introduced[3] to the codebase from now on. Also, notice that, dynamic memory allocations won't be affected by this change: "Flexible array members have incomplete type, and so the sizeof operator may not be applied. As a quirk of the original implementation of zero-length arrays, sizeof evaluates to zero."[1] sizeof(flexible-array-member) triggers a warning because flexible array members have incomplete type[1]. There are some instances of code in which the sizeof operator is being incorrectly/erroneously applied to zero-length arrays and the result is zero. Such instances may be hiding some bugs. So, this work (flexible-array member conversions) will also help to get completely rid of those sorts of issues. This issue was found with the help of Coccinelle. [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html [2] https://github.com/KSPP/linux/issues/21 [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour") Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Signed-off-by: Kalle Valo <kvalo@codeaurora.org> Link: https://lore.kernel.org/r/20200507185529.GA14639@embeddedor
78 lines
1.8 KiB
C
78 lines
1.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/******************************************************************************
|
|
*
|
|
* Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
|
|
*
|
|
* Portions of this file are derived from the ieee80211 subsystem header files.
|
|
*
|
|
* Contact Information:
|
|
* Intel Linux Wireless <ilw@linux.intel.com>
|
|
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
*
|
|
*****************************************************************************/
|
|
|
|
#ifndef __il_spectrum_h__
|
|
#define __il_spectrum_h__
|
|
enum { /* ieee80211_basic_report.map */
|
|
IEEE80211_BASIC_MAP_BSS = (1 << 0),
|
|
IEEE80211_BASIC_MAP_OFDM = (1 << 1),
|
|
IEEE80211_BASIC_MAP_UNIDENTIFIED = (1 << 2),
|
|
IEEE80211_BASIC_MAP_RADAR = (1 << 3),
|
|
IEEE80211_BASIC_MAP_UNMEASURED = (1 << 4),
|
|
/* Bits 5-7 are reserved */
|
|
|
|
};
|
|
struct ieee80211_basic_report {
|
|
u8 channel;
|
|
__le64 start_time;
|
|
__le16 duration;
|
|
u8 map;
|
|
} __packed;
|
|
|
|
enum { /* ieee80211_measurement_request.mode */
|
|
/* Bit 0 is reserved */
|
|
IEEE80211_MEASUREMENT_ENABLE = (1 << 1),
|
|
IEEE80211_MEASUREMENT_REQUEST = (1 << 2),
|
|
IEEE80211_MEASUREMENT_REPORT = (1 << 3),
|
|
/* Bits 4-7 are reserved */
|
|
};
|
|
|
|
enum {
|
|
IEEE80211_REPORT_BASIC = 0, /* required */
|
|
IEEE80211_REPORT_CCA = 1, /* optional */
|
|
IEEE80211_REPORT_RPI = 2, /* optional */
|
|
/* 3-255 reserved */
|
|
};
|
|
|
|
struct ieee80211_measurement_params {
|
|
u8 channel;
|
|
__le64 start_time;
|
|
__le16 duration;
|
|
} __packed;
|
|
|
|
struct ieee80211_info_element {
|
|
u8 id;
|
|
u8 len;
|
|
u8 data[];
|
|
} __packed;
|
|
|
|
struct ieee80211_measurement_request {
|
|
struct ieee80211_info_element ie;
|
|
u8 token;
|
|
u8 mode;
|
|
u8 type;
|
|
struct ieee80211_measurement_params params[];
|
|
} __packed;
|
|
|
|
struct ieee80211_measurement_report {
|
|
struct ieee80211_info_element ie;
|
|
u8 token;
|
|
u8 mode;
|
|
u8 type;
|
|
union {
|
|
struct ieee80211_basic_report basic[0];
|
|
} u;
|
|
} __packed;
|
|
|
|
#endif
|