Skip to content

Commit 51b2206

Browse files
attie-argentumcarlescufi
authored andcommitted
drivers: i2c: sam0: Lock bus before referencing messages
The I2C bus lock did not previously enclose the referencing of the transfers to conduct. If two attempts are made to use the bus at a similar time, then one set of messages may have been transferred twice. Signed-off-by: Attie Grande <[email protected]>
1 parent 82e0589 commit 51b2206

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/i2c/i2c_sam0.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,12 @@ static int i2c_sam0_transfer(const struct device *dev, struct i2c_msg *msgs,
389389
if (!num_msgs) {
390390
return 0;
391391
}
392-
data->num_msgs = num_msgs;
393-
data->msgs = msgs;
394392

395393
k_sem_take(&data->lock, K_FOREVER);
396394

395+
data->num_msgs = num_msgs;
396+
data->msgs = msgs;
397+
397398
for (; data->num_msgs > 0;) {
398399
if (!data->msgs->len) {
399400
if ((data->msgs->flags & I2C_MSG_RW_MASK) == I2C_MSG_READ) {

0 commit comments

Comments
 (0)