Skip to content

Commit 704ec89

Browse files
author
Joel Slebodnick
committed
mtd: spi-nor: Introduce spi_nor_match_id()
JIRA: https://issues.redhat.com/browse/RHEL-40636 commit d0ddd88 Author: Tudor Ambarus <tudor.ambarus@microchip.com> Date: Wed Apr 20 13:34:18 2022 +0300 mtd: spi-nor: Introduce spi_nor_match_id() Similar to spi_nor_match_name() extend the search of flash_info through all the manufacturers, this time doing the match by ID. There's no reason to limit the search per manufacturer yet, do it globally, search the flash in all the parts of all manufacturers in a single method. Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Signed-off-by: Pratyush Yadav <p.yadav@ti.com> Reviewed-by: Pratyush Yadav <p.yadav@ti.com> Reviewed-by: Michael Walle <michael@walle.cc> Link: https://lore.kernel.org/r/20220420103427.47867-3-tudor.ambarus@microchip.com Signed-off-by: Joel Slebodnick <jslebodn@redhat.com>
1 parent bdc0eeb commit 704ec89

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,16 +1848,21 @@ static const struct spi_nor_manufacturer *manufacturers[] = {
18481848
&spi_nor_xmc,
18491849
};
18501850

1851-
static const struct flash_info *
1852-
spi_nor_search_part_by_id(const struct flash_info *parts, unsigned int nparts,
1853-
const u8 *id)
1851+
static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
1852+
const u8 *id)
18541853
{
1855-
unsigned int i;
1854+
const struct flash_info *part;
1855+
unsigned int i, j;
18561856

1857-
for (i = 0; i < nparts; i++) {
1858-
if (parts[i].id_len &&
1859-
!memcmp(parts[i].id, id, parts[i].id_len))
1860-
return &parts[i];
1857+
for (i = 0; i < ARRAY_SIZE(manufacturers); i++) {
1858+
for (j = 0; j < manufacturers[i]->nparts; j++) {
1859+
part = &manufacturers[i]->parts[j];
1860+
if (part->id_len &&
1861+
!memcmp(part->id, id, part->id_len)) {
1862+
nor->manufacturer = manufacturers[i];
1863+
return part;
1864+
}
1865+
}
18611866
}
18621867

18631868
return NULL;
@@ -1867,7 +1872,6 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
18671872
{
18681873
const struct flash_info *info;
18691874
u8 *id = nor->bouncebuf;
1870-
unsigned int i;
18711875
int ret;
18721876

18731877
if (nor->spimem) {
@@ -1887,19 +1891,13 @@ static const struct flash_info *spi_nor_read_id(struct spi_nor *nor)
18871891
return ERR_PTR(ret);
18881892
}
18891893

1890-
for (i = 0; i < ARRAY_SIZE(manufacturers); i++) {
1891-
info = spi_nor_search_part_by_id(manufacturers[i]->parts,
1892-
manufacturers[i]->nparts,
1893-
id);
1894-
if (info) {
1895-
nor->manufacturer = manufacturers[i];
1896-
return info;
1897-
}
1894+
info = spi_nor_match_id(nor, id);
1895+
if (!info) {
1896+
dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
1897+
SPI_NOR_MAX_ID_LEN, id);
1898+
return ERR_PTR(-ENODEV);
18981899
}
1899-
1900-
dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
1901-
SPI_NOR_MAX_ID_LEN, id);
1902-
return ERR_PTR(-ENODEV);
1900+
return info;
19031901
}
19041902

19051903
static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,

0 commit comments

Comments
 (0)