Commit 2dcbfe36 authored by Jonathan Neuschäfer's avatar Jonathan Neuschäfer Committed by Tudor Ambarus

mtd: spi-nor: Refactor spi_nor_read_id()

- Don't use `tmp` for two purposes (return value, loop counter).
  Instead, use `i` for the loop counter, and `ret` for the return value.
- Don't use tabs between type and name in variable declarations,
  for consistency with other functions in spi-nor.c.
- Rewrite nested `if`s as `if (a && b)`.
- Remove `info` variable, and use spi_nor_ids[i] directly.
Signed-off-by: default avatarJonathan Neuschäfer <j.neuschaefer@gmx.net>
[tudor.ambarus@microchip.com: change i's type from int to unsigned int,
reorder local variables]
Signed-off-by: default avatarTudor Ambarus <tudor.ambarus@microchip.com>
parent df5c2100
...@@ -2733,9 +2733,9 @@ static const struct flash_info spi_nor_ids[] = { ...@@ -2733,9 +2733,9 @@ static const struct flash_info spi_nor_ids[] = {
static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
{ {
int tmp;
u8 *id = nor->bouncebuf; u8 *id = nor->bouncebuf;
const struct flash_info *info; unsigned int i;
int ret;
if (nor->spimem) { if (nor->spimem) {
struct spi_mem_op op = struct spi_mem_op op =
...@@ -2744,22 +2744,20 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor) ...@@ -2744,22 +2744,20 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
SPI_MEM_OP_NO_DUMMY, SPI_MEM_OP_NO_DUMMY,
SPI_MEM_OP_DATA_IN(SPI_NOR_MAX_ID_LEN, id, 1)); SPI_MEM_OP_DATA_IN(SPI_NOR_MAX_ID_LEN, id, 1));
tmp = spi_mem_exec_op(nor->spimem, &op); ret = spi_mem_exec_op(nor->spimem, &op);
} else { } else {
tmp = nor->controller_ops->read_reg(nor, SPINOR_OP_RDID, id, ret = nor->controller_ops->read_reg(nor, SPINOR_OP_RDID, id,
SPI_NOR_MAX_ID_LEN); SPI_NOR_MAX_ID_LEN);
} }
if (tmp) { if (ret) {
dev_dbg(nor->dev, "error %d reading JEDEC ID\n", tmp); dev_dbg(nor->dev, "error %d reading JEDEC ID\n", ret);
return ERR_PTR(tmp); return ERR_PTR(ret);
} }
for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) { for (i = 0; i < ARRAY_SIZE(spi_nor_ids) - 1; i++) {
info = &spi_nor_ids[tmp]; if (spi_nor_ids[i].id_len &&
if (info->id_len) { !memcmp(spi_nor_ids[i].id, id, spi_nor_ids[i].id_len))
if (!memcmp(info->id, id, info->id_len)) return &spi_nor_ids[i];
return &spi_nor_ids[tmp];
}
} }
dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n", dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
SPI_NOR_MAX_ID_LEN, id); SPI_NOR_MAX_ID_LEN, id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment