From 3ea5f799dd7978b7baf2edd7d2458e0c36e431fc Mon Sep 17 00:00:00 2001 From: Bram Vlerick Date: Mon, 29 Apr 2024 10:33:19 +0200 Subject: [PATCH] i2c: target: eeprom_target: add addressable size assert 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 --- drivers/i2c/target/eeprom_target.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/i2c/target/eeprom_target.c b/drivers/i2c/target/eeprom_target.c index 19953ec5559c9b..e2820749b206b9 100644 --- a/drivers/i2c/target/eeprom_target.c +++ b/drivers/i2c/target/eeprom_target.c @@ -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), \