Skip to content

Commit ef79d03

Browse files
ozbenhstewartsmith
authored andcommitted
i2c: Ensure ordering between i2c_request_send() and completion
i2c_request_send loops waiting for a flag "uc.done" set by the completion routine, and then look for a result code also set by that same completion. There is no synchronization, the completion can happen on another processor, so we need to order the stores to uc and the reads from uc so that uc.done is stored last and tested first using memory barriers. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
1 parent f737777 commit ef79d03

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

core/i2c.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <device.h>
2121
#include <opal-msg.h>
2222
#include <timebase.h>
23+
#include <processor.h>
2324

2425
static LIST_HEAD(i2c_bus_list);
2526

@@ -148,6 +149,7 @@ static void i2c_sync_request_complete(int rc, struct i2c_request *req)
148149
{
149150
struct i2c_sync_userdata *ud = req->user_data;
150151
ud->rc = rc;
152+
lwsync();
151153
ud->done = true;
152154
}
153155

@@ -222,6 +224,7 @@ int i2c_request_send(int bus_id, int dev_addr, int read_write,
222224
waited += time_to_wait;
223225
} while (!ud.done);
224226

227+
lwsync();
225228
rc = ud.rc;
226229

227230
/* error or success */

0 commit comments

Comments
 (0)