Skip to content

Commit

Permalink
i2c: designware: Fix improper usage of readl
Browse files Browse the repository at this point in the history
Kernel test robot reported incorrect type in argument 1 of readl(), but
more importantly it brought attention that MMIO accessor shouldn't be
used in this case, since req->hdr.status is part of a command-response
buffer in system memory.

Since its value may be altered by PSP outside of the scope of current
thread (somehow similar to IRQ handler case), we need to use
READ_ONCE() to ensure compiler won't optimize this call.

Fix also 'status' variable type to reflect that corresponding field in
command-response buffer is platform-independent u32.

Fixes: 78d5e9e ("i2c: designware: Add AMD PSP I2C bus support")
Signed-off-by: Jan Dabros <jsd@semihalf.com>
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Wolfram Sang <wsa@kernel.org>
  • Loading branch information
Jan Dabros authored and Wolfram Sang committed Mar 1, 2022
1 parent d870355 commit 17ba1e8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/i2c/busses/i2c-designware-amdpsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ static int psp_send_cmd(struct psp_i2c_req *req)
/* Helper to verify status returned by PSP */
static int check_i2c_req_sts(struct psp_i2c_req *req)
{
int status;
u32 status;

status = readl(&req->hdr.status);
/* Status field in command-response buffer is updated by PSP */
status = READ_ONCE(req->hdr.status);

switch (status) {
case PSP_I2C_REQ_STS_OK:
Expand Down

0 comments on commit 17ba1e8

Please sign in to comment.