Skip to content

Commit

Permalink
UPSTREAM: sf: Avoid allocating memory on every read operation
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jon Lin <[email protected]>
(cherry picked from commit 97f5710)
  • Loading branch information
sjg20 authored and keveryang committed Jul 5, 2019
1 parent 583deaf commit 50d09c0
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions drivers/mtd/spi/spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
size_t len, void *data)
{
struct spi_slave *spi = flash->spi;
u8 *cmd, cmdsz;
u8 cmdsz;
u32 remain_len, read_len, read_addr;
int bank_sel = 0;
int ret = -1;
Expand All @@ -491,11 +491,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
}

cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte;
cmd = calloc(1, cmdsz);
if (!cmd) {
debug("SF: Failed to allocate cmd\n");
return -ENOMEM;
}
u8 cmd[cmdsz];

cmd[0] = flash->read_cmd;
while (len) {
Expand Down Expand Up @@ -538,7 +534,6 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
ret = clean_bar(flash);
#endif

free(cmd);
return ret;
}

Expand Down

0 comments on commit 50d09c0

Please sign in to comment.