Skip to content

Commit a0eb093

Browse files
duynguyenxacfriedt
authored andcommitted
drivers: i2c: Move merge buffer to driver data for RA i2c_sci_b
The merge buffer was previously declared as a static variable, causing it to be shared across all I2C instances and risking data corruption when used concurrently. Move the buffer into the driver data to make it instance-specific and avoid race conditions. Signed-off-by: Duy Nguyen <[email protected]>
1 parent 0ce50a2 commit a0eb093

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/i2c/i2c_renesas_ra_sci_b.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct sci_b_i2c_data {
4242
struct k_sem complete_sem;
4343
i2c_master_event_t event;
4444
uint32_t dev_config;
45+
uint8_t merge_buf[I2C_MAX_MSG_LEN];
4546

4647
#ifdef CONFIG_I2C_CALLBACK
4748
uint16_t addr;
@@ -125,6 +126,9 @@ static int renesas_ra_sci_b_i2c_transfer(const struct device *dev, struct i2c_ms
125126
struct i2c_msg *current, *next;
126127
fsp_err_t fsp_err;
127128
int ret;
129+
uint8_t *merge_buf = data->merge_buf;
130+
struct i2c_msg tmp_msg;
131+
uint16_t tmp_len;
128132

129133
if (!num_msgs) {
130134
return 0;
@@ -134,12 +138,9 @@ static int renesas_ra_sci_b_i2c_transfer(const struct device *dev, struct i2c_ms
134138
if (num_msgs == 2) {
135139
if (msgs[0].len == 1U && !(msgs[0].flags & I2C_MSG_READ) &&
136140
!(msgs[1].flags & I2C_MSG_READ)) {
137-
uint16_t tmp_len = msgs[0].len + msgs[1].len;
141+
tmp_len = msgs[0].len + msgs[1].len;
138142

139143
if (tmp_len <= I2C_MAX_MSG_LEN) {
140-
static uint8_t merge_buf[I2C_MAX_MSG_LEN];
141-
struct i2c_msg tmp_msg;
142-
143144
memcpy(&merge_buf[0], msgs[0].buf, msgs[0].len);
144145
memcpy(&merge_buf[msgs[0].len], msgs[1].buf, msgs[1].len);
145146
tmp_msg.buf = &merge_buf[0];

0 commit comments

Comments
 (0)