diff options
author | Bill Richardson <wfrichar@chromium.org> | 2013-07-30 17:26:20 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-31 12:33:31 -0700 |
commit | af777297370e971bd4ae64e0e947cb5a1774dbfe (patch) | |
tree | 282a090d2431626ce01e4940c4a4ca722d70166e /board/host/board.c | |
parent | f6799258c3842ef855bf1516066464431b1b1a7d (diff) | |
download | chrome-ec-af777297370e971bd4ae64e0e947cb5a1774dbfe.tar.gz |
Add build-time checks on board-specific array sizes.
We've been declaring a bunch of statically-sized arrays:
extern struct foo_t foo[FOO_COUNT];
And then initializing them like so:
struct foo_t foo[FOO_COUNT] = {
/* blah */
};
That only catches cases where we initialize with too many entries. It
doesn't catch cases where we haven't initialized enough. This change tests
for both cases like so:
extern struct foo_t foo[];
struct foo_t foo[] = {
/* blah */
};
BUILD_ASSERT(ARRAY_SIZE(foo) == FOO_COUNT);
The affected arrays are:
adc_channels[ADC_CH_COUNT]
gpio_list[GPIO_COUNT]
temp_sensors[TEMP_SENSOR_COUNT]
x86_signal_list[X86_SIGNAL_COUNT]
i2c_ports[I2C_PORTS_USED]
BUG=chrome-os-partner:18343
BRANCH=falco,peppy
TEST=build all platforms
All platforms should still build, all tests should still pass.
Change-Id: Ibb16dc3201f32df7cdc875648e89ba4ffb09f733
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/63833
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'board/host/board.c')
-rw-r--r-- | board/host/board.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/board/host/board.c b/board/host/board.c index 9e81cf60d3..13389ce001 100644 --- a/board/host/board.c +++ b/board/host/board.c @@ -6,10 +6,11 @@ #include "gpio.h" #include "temp_sensor.h" +#include "util.h" #define MOCK_GPIO(x) {#x, 0, 0, 0, 0} -const struct gpio_info gpio_list[GPIO_COUNT] = { +const struct gpio_info gpio_list[] = { MOCK_GPIO(EC_INT), MOCK_GPIO(LID_OPEN), MOCK_GPIO(POWER_BUTTON_L), @@ -17,6 +18,7 @@ const struct gpio_info gpio_list[GPIO_COUNT] = { MOCK_GPIO(ENTERING_RW), MOCK_GPIO(AC_PRESENT), }; +BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT); static int dummy_temp_get_val(int idx, int *temp_ptr) { @@ -24,8 +26,9 @@ static int dummy_temp_get_val(int idx, int *temp_ptr) return EC_SUCCESS; } -const struct temp_sensor_t temp_sensors[TEMP_SENSOR_COUNT] = { +const struct temp_sensor_t temp_sensors[] = { {"CPU", TEMP_SENSOR_TYPE_CPU, dummy_temp_get_val, 0, 3}, {"Board", TEMP_SENSOR_TYPE_BOARD, dummy_temp_get_val, 0, 3}, {"Case", TEMP_SENSOR_TYPE_CASE, dummy_temp_get_val, 0, 0}, }; +BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); |