Skip to content

Commit 5052919

Browse files
wouterhkartben
authored andcommitted
drivers: i2c: stm32: Fix size calculation of n_timings
`timings` is an array of `struct i2c_config_timing` (3 x `uint32_t`). `i2c_timings_##index` is an array of `uint32_t` (hence the cast when it is assigned to `timings`). Therefore `ARRAY_SIZE(i2c_timings_##index)` is off by a factor 3 when used for `n_timings`. Parentheses around the second `sizeof` are there to silence the gcc warning (-Wsizeof-array-div) that warns about not computing the size of `i2c_timings_##index`. Signed-off-by: Wouter Horré <[email protected]>
1 parent 17c00ce commit 5052919

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/i2c/i2c_ll_stm32.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,8 @@ static const struct i2c_stm32_config i2c_stm32_cfg_##index = { \
550550
.sda = GPIO_DT_SPEC_INST_GET_OR(index, sda_gpios, {0}),)) \
551551
IF_ENABLED(DT_HAS_COMPAT_STATUS_OKAY(st_stm32_i2c_v2), \
552552
(.timings = (const struct i2c_config_timing *) i2c_timings_##index, \
553-
.n_timings = ARRAY_SIZE(i2c_timings_##index),)) \
553+
.n_timings = \
554+
sizeof(i2c_timings_##index) / (sizeof(struct i2c_config_timing)),)) \
554555
I2C_DMA_INIT(index, tx) \
555556
I2C_DMA_INIT(index, rx) \
556557
}; \

0 commit comments

Comments
 (0)