From 2fb228c198d2581df4c90bd94f0240737a9db134 Mon Sep 17 00:00:00 2001 From: Bill Richardson Date: Mon, 7 Oct 2013 13:20:58 -0700 Subject: [PATCH] cleanup: Don't use [N] = {} when initializing arrays If we do this: enum foo_v { FOO_A, FOO_B, FOO_COUNT }; struct foo_t foo[] = { {...}, {...}, }; BUILD_ASSERT(ARRAY_SIZE(foo) == FOO_COUNT); Then we can be sure we're at least initialized all the elements of foo, although there's no particular guarantee that the order is correct. However, if we use this: struct foo_t foo[] = { [FOO_A] = {...}, [FOO_B] = {...}, }; and we accidentally get one wrong: struct foo_t foo[] = { [FOO_B] = {...}, [FOO_B] = {...}, }; Then the assertion still passes, but we've only initialized one element. Don't do that. BUG=chrome-os-partner:18343 BRANCH=none TEST=manual Refactoring only. Build everything. It should still work. Change-Id: I58f659207990f18c6fb74b1cac2ec1163cdb07ea Signed-off-by: Bill Richardson Reviewed-on: https://chromium-review.googlesource.com/172115 Reviewed-by: Randall Spangler --- board/bolt/board.c | 6 +++--- board/falco/board.c | 4 ++-- board/kirby/board.c | 8 ++++---- board/link/board.c | 6 +++--- board/peppy/board.c | 4 ++-- board/pit/board.c | 6 +++--- board/puppy/board.c | 6 +++--- board/rambi/board.c | 6 +++--- board/samus/board.c | 6 +++--- board/slippy/board.c | 4 ++-- board/snow/board.c | 6 +++--- board/spring/board.c | 5 ++--- 12 files changed, 33 insertions(+), 34 deletions(-) diff --git a/board/bolt/board.c b/board/bolt/board.c index 1a89534388..3d88c762d8 100644 --- a/board/bolt/board.c +++ b/board/bolt/board.c @@ -181,10 +181,10 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_FAN] = {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, - [PWM_CH_KBLIGHT] = {4, 0}, + {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, + {4, 0}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/falco/board.c b/board/falco/board.c index adc6cbddfb..b7f434d056 100644 --- a/board/falco/board.c +++ b/board/falco/board.c @@ -184,9 +184,9 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_FAN] = {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, + {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/kirby/board.c b/board/kirby/board.c index 4cac7b6d9f..ca88e1416f 100644 --- a/board/kirby/board.c +++ b/board/kirby/board.c @@ -106,13 +106,13 @@ const struct gpio_alt_func gpio_alt_funcs[] = { }; const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_CHG_Y] = {STM32_TIM(3), STM32_TIM_CH(1), PWM_CONFIG_ACTIVE_LOW, + {STM32_TIM(3), STM32_TIM_CH(1), PWM_CONFIG_ACTIVE_LOW, GPIO_CHG_LED_Y}, - [PWM_CH_CHG_G] = {STM32_TIM(3), STM32_TIM_CH(2), PWM_CONFIG_ACTIVE_LOW, + {STM32_TIM(3), STM32_TIM_CH(2), PWM_CONFIG_ACTIVE_LOW, GPIO_CHG_LED_G}, - [PWM_CH_CHG_R] = {STM32_TIM(3), STM32_TIM_CH(3), PWM_CONFIG_ACTIVE_LOW, + {STM32_TIM(3), STM32_TIM_CH(3), PWM_CONFIG_ACTIVE_LOW, GPIO_CHG_LED_R}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/link/board.c b/board/link/board.c index 2b4fb9aeaf..4d6edbb2ed 100644 --- a/board/link/board.c +++ b/board/link/board.c @@ -182,10 +182,10 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_FAN] = {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, - [PWM_CH_KBLIGHT] = {1, 0}, + {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, + {1, 0}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/peppy/board.c b/board/peppy/board.c index 730e1e17d9..f1d55dd738 100644 --- a/board/peppy/board.c +++ b/board/peppy/board.c @@ -176,9 +176,9 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_FAN] = {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, + {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/pit/board.c b/board/pit/board.c index 9f4ca08a1e..ba9fb7252d 100644 --- a/board/pit/board.c +++ b/board/pit/board.c @@ -124,10 +124,10 @@ struct keyboard_scan_config keyscan_config = { }, }; -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_POWER_LED] = {STM32_TIM(2), STM32_TIM_CH(3), - PWM_CONFIG_ACTIVE_LOW, GPIO_LED_POWER_L}, + {STM32_TIM(2), STM32_TIM_CH(3), + PWM_CONFIG_ACTIVE_LOW, GPIO_LED_POWER_L}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/puppy/board.c b/board/puppy/board.c index f874ed2ad5..db275818ab 100644 --- a/board/puppy/board.c +++ b/board/puppy/board.c @@ -109,10 +109,10 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_POWER_LED] = {STM32_TIM(2), STM32_TIM_CH(3), - PWM_CONFIG_ACTIVE_LOW, GPIO_LED_POWER_L}, + {STM32_TIM(2), STM32_TIM_CH(3), + PWM_CONFIG_ACTIVE_LOW, GPIO_LED_POWER_L}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/rambi/board.c b/board/rambi/board.c index 7a6f926763..0ba70a89be 100644 --- a/board/rambi/board.c +++ b/board/rambi/board.c @@ -150,10 +150,10 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_LED_GREEN] = {4, PWM_CONFIG_ACTIVE_LOW}, - [PWM_CH_LED_RED] = {3, PWM_CONFIG_ACTIVE_LOW}, + {4, PWM_CONFIG_ACTIVE_LOW}, + {3, PWM_CONFIG_ACTIVE_LOW}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/samus/board.c b/board/samus/board.c index e649836b89..f729ce46f8 100644 --- a/board/samus/board.c +++ b/board/samus/board.c @@ -180,10 +180,10 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_FAN] = {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, - [PWM_CH_KBLIGHT] = {4, 0}, + {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, + {4, 0}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/slippy/board.c b/board/slippy/board.c index df46ddfb02..cf937ead4f 100644 --- a/board/slippy/board.c +++ b/board/slippy/board.c @@ -174,9 +174,9 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_FAN] = {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, + {CONFIG_FAN_CH_CPU, PWM_CONFIG_HAS_RPM_MODE}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/snow/board.c b/board/snow/board.c index 4120356175..cf09e189e9 100644 --- a/board/snow/board.c +++ b/board/snow/board.c @@ -122,10 +122,10 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_POWER_LED] = {STM32_TIM(2), STM32_TIM_CH(2), - PWM_CONFIG_ACTIVE_LOW, GPIO_LED_POWER_L}, + {STM32_TIM(2), STM32_TIM_CH(2), + PWM_CONFIG_ACTIVE_LOW, GPIO_LED_POWER_L}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); diff --git a/board/spring/board.c b/board/spring/board.c index fd9acaf6d5..09e943d8f7 100644 --- a/board/spring/board.c +++ b/board/spring/board.c @@ -120,10 +120,9 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); -/* PWM channels */ +/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ const struct pwm_t pwm_channels[] = { - [PWM_CH_ILIM] = {STM32_TIM(3), STM32_TIM_CH(1), 0, - GPIO_ILIM}, + {STM32_TIM(3), STM32_TIM_CH(1), 0, GPIO_ILIM}, }; BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);