[U-Boot] [Patch V7 1/4] spi: fsl_qspi: fix compile warning for 64-bit platform

From: Gong Qianyu Qianyu.Gong@freescale.com
This patch fixes the following compile warning: drivers/spi/fsl_qspi.c: In function 'fsl_qspi_probe': drivers/spi/fsl_qspi.c:937:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] priv->regs = (struct fsl_qspi_regs *)plat->reg_base; ^ Just make the cast explicit.
Signed-off-by: Gong Qianyu Qianyu.Gong@freescale.com --- V6-V7: - No change. V5: - Use uintptr_t instead of unsigned long. V4: - Revise the commit message. V2-V3: - No change.
drivers/spi/fsl_qspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c index 542b6cf..38e5900 100644 --- a/drivers/spi/fsl_qspi.c +++ b/drivers/spi/fsl_qspi.c @@ -936,7 +936,7 @@ static int fsl_qspi_probe(struct udevice *bus)
dm_spi_bus->max_hz = plat->speed_hz;
- priv->regs = (struct fsl_qspi_regs *)plat->reg_base; + priv->regs = (struct fsl_qspi_regs *)(uintptr_t)plat->reg_base; priv->flags = plat->flags;
priv->speed_hz = plat->speed_hz;

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 --- V7: - Fix type of "size" and so "size -= 4" is also fixed. - Not use min() to avoid a compile warning of type cast. V6: - Use min() to simplify code. V2-V5: - No change.
drivers/spi/fsl_qspi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c index 38e5900..3553e00 100644 --- a/drivers/spi/fsl_qspi.c +++ b/drivers/spi/fsl_qspi.c @@ -477,8 +477,8 @@ static void qspi_op_rdbank(struct fsl_qspi_priv *priv, u8 *rxbuf, u32 len) static void qspi_op_rdid(struct fsl_qspi_priv *priv, u32 *rxbuf, u32 len) { struct fsl_qspi_regs *regs = priv->regs; - u32 mcr_reg, rbsr_reg, data; - int i, size; + u32 mcr_reg, rbsr_reg, data, size; + int i;
mcr_reg = qspi_read32(priv->flags, ®s->mcr); qspi_write32(priv->flags, ®s->mcr, @@ -494,15 +494,15 @@ static void qspi_op_rdid(struct fsl_qspi_priv *priv, u32 *rxbuf, u32 len) ;
i = 0; - size = len; - while ((RX_BUFFER_SIZE >= size) && (size > 0)) { + while ((RX_BUFFER_SIZE >= len) && (len > 0)) { rbsr_reg = qspi_read32(priv->flags, ®s->rbsr); if (rbsr_reg & QSPI_RBSR_RDBFL_MASK) { data = qspi_read32(priv->flags, ®s->rbdr[i]); data = qspi_endian_xchg(data); - memcpy(rxbuf, &data, 4); + size = (len < 4) ? len : 4; + memcpy(rxbuf, &data, size); + len -= size; rxbuf++; - size -= 4; i++; } }

On 01/25/2016 11: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
V7:
- Fix type of "size" and so "size -= 4" is also fixed.
- Not use min() to avoid a compile warning of type cast.
V6:
- Use min() to simplify code.
V2-V5:
- No change.
drivers/spi/fsl_qspi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
Applied to u-boot-fsl-qoriq master. Awaiting upstream.
Thanks.
York

From: Gong Qianyu Qianyu.Gong@freescale.com
In current driver, we always copy 4 bytes to the dest memory. Actually the dest memory may be shorter than 4 bytes. Add an argument to indicate the dest memory length. Avoid writing memory outside of the bounds.
Signed-off-by: Gong Qianyu Qianyu.Gong@freescale.com --- V3-V7: - No change. V2: - New patch.
drivers/spi/fsl_qspi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c index 02aaee3..c3b2569 100644 --- a/drivers/spi/fsl_qspi.c +++ b/drivers/spi/fsl_qspi.c @@ -639,7 +639,7 @@ static void qspi_op_write(struct fsl_qspi_priv *priv, u8 *txbuf, u32 len) qspi_write32(priv->flags, ®s->mcr, mcr_reg); }
-static void qspi_op_rdsr(struct fsl_qspi_priv *priv, u32 *rxbuf) +static void qspi_op_rdsr(struct fsl_qspi_priv *priv, void *rxbuf, u32 len) { struct fsl_qspi_regs *regs = priv->regs; u32 mcr_reg, reg, data; @@ -662,7 +662,7 @@ static void qspi_op_rdsr(struct fsl_qspi_priv *priv, u32 *rxbuf) if (reg & QSPI_RBSR_RDBFL_MASK) { data = qspi_read32(priv->flags, ®s->rbdr[0]); data = qspi_endian_xchg(data); - memcpy(rxbuf, &data, 4); + memcpy(rxbuf, &data, len); qspi_write32(priv->flags, ®s->mcr, qspi_read32(priv->flags, ®s->mcr) | QSPI_MCR_CLR_RXF_MASK); @@ -751,7 +751,7 @@ int qspi_xfer(struct fsl_qspi_priv *priv, unsigned int bitlen, } else if (priv->cur_seqid == QSPI_CMD_RDID) qspi_op_rdid(priv, din, bytes); else if (priv->cur_seqid == QSPI_CMD_RDSR) - qspi_op_rdsr(priv, din); + qspi_op_rdsr(priv, din, bytes); #ifdef CONFIG_SPI_FLASH_BAR else if ((priv->cur_seqid == QSPI_CMD_BRRD) || (priv->cur_seqid == QSPI_CMD_RDEAR)) {

On 01/25/2016 11:15 PM, Gong Qianyu wrote:
From: Gong Qianyu Qianyu.Gong@freescale.com
In current driver, we always copy 4 bytes to the dest memory. Actually the dest memory may be shorter than 4 bytes. Add an argument to indicate the dest memory length. Avoid writing memory outside of the bounds.
Signed-off-by: Gong Qianyu Qianyu.Gong@freescale.com
V3-V7:
- No change.
V2:
- New patch.
drivers/spi/fsl_qspi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Applied to u-boot-fsl-qoriq master. Awaiting upstream.
Thanks.
York

From: Gong Qianyu Qianyu.Gong@freescale.com
It might be missed when converting spi_flash_probe() in cmd_sf.c.
This patch refers to commit fbb099183e3a ("dm: Convert spi_flash_probe() and 'sf probe' to use driver model").
Signed-off-by: Gong Qianyu Qianyu.Gong@freescale.com --- V6-V7: - No change. V5: - Revise commit message. V4: - Use CONFIG_ENV_* instead of CONFIG_SF_*. - Remove the variables and call the macros directly. - Use set_default_env instead of print info. V3: - Remove redundant operations for saveenv() V2: - New patch.
common/env_sf.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/common/env_sf.c b/common/env_sf.c index 9409831..892e6cb 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -16,6 +16,7 @@ #include <spi_flash.h> #include <search.h> #include <errno.h> +#include <dm/device-internal.h>
#ifndef CONFIG_ENV_SPI_BUS # define CONFIG_ENV_SPI_BUS 0 @@ -51,6 +52,19 @@ int saveenv(void) char *saved_buffer = NULL, flag = OBSOLETE_FLAG; u32 saved_size, saved_offset, sector = 1; int ret; +#ifdef CONFIG_DM_SPI_FLASH + struct udevice *new; + + ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, + CONFIG_ENV_SPI_MAX_HZ, + CONFIG_ENV_SPI_MODE, &new); + if (ret) { + set_default_env("!spi_flash_probe_bus_cs() failed"); + return 1; + } + + env_flash = dev_get_uclass_priv(new); +#else
if (!env_flash) { env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, @@ -61,6 +75,7 @@ int saveenv(void) return 1; } } +#endif
ret = env_export(&env_new); if (ret) @@ -227,6 +242,19 @@ int saveenv(void) char *saved_buffer = NULL; int ret = 1; env_t env_new; +#ifdef CONFIG_DM_SPI_FLASH + struct udevice *new; + + ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, + CONFIG_ENV_SPI_MAX_HZ, + CONFIG_ENV_SPI_MODE, &new); + if (ret) { + set_default_env("!spi_flash_probe_bus_cs() failed"); + return 1; + } + + env_flash = dev_get_uclass_priv(new); +#else
if (!env_flash) { env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, @@ -237,6 +265,7 @@ int saveenv(void) return 1; } } +#endif
/* Is the sector larger than the env (i.e. embedded) */ if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {

On 01/25/2016 11:15 PM, Gong Qianyu wrote:
From: Gong Qianyu Qianyu.Gong@freescale.com
It might be missed when converting spi_flash_probe() in cmd_sf.c.
This patch refers to commit fbb099183e3a ("dm: Convert spi_flash_probe() and 'sf probe' to use driver model").
Signed-off-by: Gong Qianyu Qianyu.Gong@freescale.com
V6-V7:
- No change.
V5:
- Revise commit message.
V4:
- Use CONFIG_ENV_* instead of CONFIG_SF_*.
- Remove the variables and call the macros directly.
- Use set_default_env instead of print info.
V3:
- Remove redundant operations for saveenv()
V2:
- New patch.
common/env_sf.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
Applied to u-boot-fsl-qoriq master. Awaiting upstream.
Thanks.
York

On 01/25/2016 11:15 PM, Gong Qianyu wrote:
From: Gong Qianyu Qianyu.Gong@freescale.com
This patch fixes the following compile warning: drivers/spi/fsl_qspi.c: In function 'fsl_qspi_probe': drivers/spi/fsl_qspi.c:937:15: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast] priv->regs = (struct fsl_qspi_regs *)plat->reg_base; ^ Just make the cast explicit.
Signed-off-by: Gong Qianyu Qianyu.Gong@freescale.com
V6-V7:
- No change.
V5:
- Use uintptr_t instead of unsigned long.
V4:
- Revise the commit message.
V2-V3:
- No change.
drivers/spi/fsl_qspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied to u-boot-fsl-qoriq master. Awaiting upstream.
Thanks.
York
participants (2)
-
Gong Qianyu
-
york sun