All of lore.kernel.org
 help / color / mirror / Atom feed
From: york sun <york.sun@nxp.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [Patch V4 2/4] spi: fsl_qspi: Fix qspi_op_rdid memcpy issue
Date: Tue, 19 Jan 2016 18:47:25 +0000	[thread overview]
Message-ID: <AM4PR0401MB1732C21C2B7A1CFD9AE5B7729AC10@AM4PR0401MB1732.eurprd04.prod.outlook.com> (raw)
In-Reply-To: 1452478010-5958-1-git-send-email-Qianyu.Gong@nxp.com

On 01/10/2016 06:15 PM, Gong Qianyu wrote:
> From: Gong Qianyu <Qianyu.Gong@freescale.com>
> 
> In current driver everytime we memcpy 4 bytes to the dest memory
> regardless of the remaining length.
> This patch adds checking the remaining length before memcpy.
> If the length is shorter than 4 bytes, memcpy the actual length of data
> to the dest memory.
> 
> Signed-off-by: Gong Qianyu <Qianyu.Gong@freescale.com>
> ---
> V2-V4:
>  - No change.
>  
>  drivers/spi/fsl_qspi.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c
> index 9f23c10..4d58211 100644
> --- a/drivers/spi/fsl_qspi.c
> +++ b/drivers/spi/fsl_qspi.c
> @@ -500,7 +500,10 @@ static void qspi_op_rdid(struct fsl_qspi_priv *priv, u32 *rxbuf, u32 len)
>  		if (rbsr_reg & QSPI_RBSR_RDBFL_MASK) {
>  			data = qspi_read32(priv->flags, &regs->rbdr[i]);
>  			data = qspi_endian_xchg(data);
> -			memcpy(rxbuf, &data, 4);
> +			if (size < 4)
> +				memcpy(rxbuf, &data, size);
> +			else
> +				memcpy(rxbuf, &data, 4);
>  			rxbuf++;
>  			size -= 4;
>  			i++;
> 

Doesn't the line "size -= 4" need a fix as well? I guess it runs OK for checking
(size > 0), but it looks odd.

York

  reply	other threads:[~2016-01-19 18:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-11  2:06 [U-Boot] [Patch V4 2/4] spi: fsl_qspi: Fix qspi_op_rdid memcpy issue Gong Qianyu
2016-01-19 18:47 ` york sun [this message]
2016-01-20  3:28   ` Qianyu Gong

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=AM4PR0401MB1732C21C2B7A1CFD9AE5B7729AC10@AM4PR0401MB1732.eurprd04.prod.outlook.com \
    --to=york.sun@nxp.com \
    --cc=u-boot@lists.denx.de \
    /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.