Skip to content

Commit

Permalink
i2c: target: eeprom_target: add addressable size assert
Browse files Browse the repository at this point in the history
Add build-time assert to check if the size defined is actually addressable.
i.e: if address-width is set to 8, the maximum addressable size is 256
bytes.

Signed-off-by: Bram Vlerick <[email protected]>
  • Loading branch information
bravl authored and carlescufi committed May 30, 2024
1 parent 52ee175 commit 3ea5f79
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/i2c/target/eeprom_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ static int i2c_eeprom_target_init(const struct device *dev)
static uint8_t \
i2c_eeprom_target_##inst##_buffer[(DT_INST_PROP(inst, size))]; \
\
BUILD_ASSERT(DT_INST_PROP(inst, size) <= \
(1 << DT_INST_PROP_OR(inst, address_width, 8)), \
"size must be <= than 2^address_width"); \
\
static const struct i2c_eeprom_target_config \
i2c_eeprom_target_##inst##_cfg = { \
.bus = I2C_DT_SPEC_INST_GET(inst), \
Expand Down

0 comments on commit 3ea5f79

Please sign in to comment.