All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Jan Dabros <jsd@semihalf.com>
Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	jarkko.nikula@linux.intel.com, wsa@kernel.org,
	rrangel@chromium.org, upstream@semihalf.com,
	kernel test robot <lkp@intel.com>
Subject: Re: [PATCH -next] i2c: designware: Fix improper usage of readl
Date: Wed, 23 Feb 2022 17:07:39 +0200	[thread overview]
Message-ID: <YhZNu0pHKiK9Vf55@smile.fi.intel.com> (raw)
In-Reply-To: <20220218133348.628962-1-jsd@semihalf.com>

On Fri, Feb 18, 2022 at 02:33:48PM +0100, Jan Dabros wrote:
> 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.

Thanks for the fix, seems reasonable to me.
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Signed-off-by: Jan Dabros <jsd@semihalf.com>
> Reported-by: kernel test robot <lkp@intel.com>
> ---
>  drivers/i2c/busses/i2c-designware-amdpsp.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-designware-amdpsp.c b/drivers/i2c/busses/i2c-designware-amdpsp.c
> index 752e0024db03..c64e459afb5c 100644
> --- a/drivers/i2c/busses/i2c-designware-amdpsp.c
> +++ b/drivers/i2c/busses/i2c-designware-amdpsp.c
> @@ -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:
> -- 
> 2.35.1.265.g69c8d7142f-goog
> 

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2022-02-23 15:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 13:33 [PATCH -next] i2c: designware: Fix improper usage of readl Jan Dabros
2022-02-23 15:07 ` Andy Shevchenko [this message]
2022-02-24 13:01   ` Jarkko Nikula
2022-03-01 15:15 ` Wolfram Sang
2022-03-01 17:29   ` Jan Dąbroś
2022-03-01 19:29     ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YhZNu0pHKiK9Vf55@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=jsd@semihalf.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=rrangel@chromium.org \
    --cc=upstream@semihalf.com \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.