UPSTREAM: sf: Avoid allocating memory on every read operation
At present spi_flash_cmd_read_ops() allocates and frees a few bytes of memory every time it is called. It is faster to use the stack for this and this is now supported by the minimum GCC version required by U-Boot. Remove the allocation and use a variable-sized array instead. Change-Id: I1c59601b4d56cd941784cbdac830a562c1491bbd Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Jon Lin <jon.lin@rock-chips.com> (cherry picked from commit 97f57109bb750d0b2908d6ecd4aef3801baf1cf2)
This commit is contained in:
parent
583deafe1b
commit
50d09c0bde
|
|
@ -471,7 +471,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
|
||||||
size_t len, void *data)
|
size_t len, void *data)
|
||||||
{
|
{
|
||||||
struct spi_slave *spi = flash->spi;
|
struct spi_slave *spi = flash->spi;
|
||||||
u8 *cmd, cmdsz;
|
u8 cmdsz;
|
||||||
u32 remain_len, read_len, read_addr;
|
u32 remain_len, read_len, read_addr;
|
||||||
int bank_sel = 0;
|
int bank_sel = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
@ -491,11 +491,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte;
|
cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte;
|
||||||
cmd = calloc(1, cmdsz);
|
u8 cmd[cmdsz];
|
||||||
if (!cmd) {
|
|
||||||
debug("SF: Failed to allocate cmd\n");
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd[0] = flash->read_cmd;
|
cmd[0] = flash->read_cmd;
|
||||||
while (len) {
|
while (len) {
|
||||||
|
|
@ -538,7 +534,6 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
|
||||||
ret = clean_bar(flash);
|
ret = clean_bar(flash);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
free(cmd);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue