Skip to content

Commit 1b00b86

Browse files
committed
drivers: i2c: Call correct I2C device definition macros
If CONFIG_I2C_STATS is enabled, the device state for all I2C controller drivers must contain the I2C stats. This space is allocated by calling Z_I2C_INIT_FN as part of the device definition; this is done automatically when using I2C_DEVICE_DT_DEFINE instead of DEVICE_DT_DEFINE. If space for statistics is not properly allocated but CONFIG_I2C_STATS is enabled, an unexpected write to memory outside of the stats region may occur on an I2C transfer. This commit uses I2C_DEVICE_DT_DEFINE or I2C_DEVICE_DT_INST_DEFINE for all in-tree SPI controller drivers that do not already. Signed-off-by: Dane Wagner <[email protected]>
1 parent f7ff830 commit 1b00b86

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

drivers/i2c/gpio_i2c_switch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static int gpio_i2c_switch_init(const struct device *dev)
9191
.gpio = GPIO_DT_SPEC_GET(DT_DRV_INST(inst), gpios), \
9292
}; \
9393
\
94-
DEVICE_DT_INST_DEFINE(inst, gpio_i2c_switch_init, device_pm_control_nop, \
94+
I2C_DEVICE_DT_INST_DEFINE(inst, gpio_i2c_switch_init, device_pm_control_nop, \
9595
&gpio_i2c_switch_dev_data_##inst, &gpio_i2c_switch_dev_cfg_##inst, \
9696
POST_KERNEL, CONFIG_I2C_INIT_PRIORITY, &gpio_i2c_switch_api_funcs);
9797

drivers/i2c/i2c_ene_kb1200.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static int i2c_kb1200_init(const struct device *dev)
352352
.fsmbm = (struct fsmbm_regs *)DT_INST_REG_ADDR(inst), \
353353
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
354354
}; \
355-
DEVICE_DT_INST_DEFINE(inst, &i2c_kb1200_init, NULL, &i2c_kb1200_data_##inst, \
355+
I2C_DEVICE_DT_INST_DEFINE(inst, &i2c_kb1200_init, NULL, &i2c_kb1200_data_##inst, \
356356
&i2c_kb1200_config_##inst, PRE_KERNEL_1, \
357357
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &i2c_kb1200_api);
358358

drivers/i2c/i2c_mchp_mss.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ static void mss_i2c_irq_handler(const struct device *dev)
382382
.clock_freq = DT_INST_PROP(n, clock_frequency), \
383383
}; \
384384
\
385-
DEVICE_DT_INST_DEFINE(n, mss_i2c_init_##n, NULL, &mss_i2c_data_##n, &mss_i2c_config_##n, \
386-
PRE_KERNEL_1, CONFIG_I2C_INIT_PRIORITY, &mss_i2c_driver_api);
385+
I2C_DEVICE_DT_INST_DEFINE(n, mss_i2c_init_##n, NULL, &mss_i2c_data_##n, \
386+
&mss_i2c_config_##n, PRE_KERNEL_1, CONFIG_I2C_INIT_PRIORITY, \
387+
&mss_i2c_driver_api);
387388

388389
DT_INST_FOREACH_STATUS_OKAY(MSS_I2C_INIT)

drivers/i2c/i2c_sc18im704.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static const struct i2c_driver_api i2c_sc18im_driver_api = {
340340
.i2c_config = I2C_MODE_CONTROLLER | (I2C_SPEED_STANDARD << I2C_SPEED_SHIFT), \
341341
}; \
342342
\
343-
DEVICE_DT_INST_DEFINE(n, i2c_sc18im_init, NULL, \
343+
I2C_DEVICE_DT_INST_DEFINE(n, i2c_sc18im_init, NULL, \
344344
&i2c_sc18im_data_##n, &i2c_sc18im_config_##n, \
345345
POST_KERNEL, CONFIG_I2C_SC18IM704_INIT_PRIORITY, \
346346
&i2c_sc18im_driver_api);

0 commit comments

Comments
 (0)