@@ -661,13 +661,26 @@ static const struct spi_device_id *spi_nor_read_id(struct spi_nor *nor)
ext_jedec = id[3] << 8 | id[4];
- for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
- info = (void *)spi_nor_ids[tmp].driver_data;
- if (info->jedec_id == jedec) {
- if (info->ext_id == 0 || info->ext_id == ext_jedec)
+ /*
+ * First let's look for entries with ext_id only. We don't want some
+ * generic entry to take a precedence over more specific ones.
+ */
+ if (ext_jedec) {
+ for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
+ info = (void *)spi_nor_ids[tmp].driver_data;
+ if (info->jedec_id == jedec &&
+ info->ext_id == ext_jedec)
return &spi_nor_ids[tmp];
}
}
+
+ /* Now check more generic entries (without ext_id) */
+ for (tmp = 0; tmp < ARRAY_SIZE(spi_nor_ids) - 1; tmp++) {
+ info = (void *)spi_nor_ids[tmp].driver_data;
+ if (info->jedec_id == jedec && !info->ext_id)
+ return &spi_nor_ids[tmp];
+ }
+
dev_err(nor->dev, "unrecognized JEDEC id %06x\n", jedec);
return ERR_PTR(-ENODEV);
}
With few entries sharing the same JEDEC ID it could happen the less specific one would be picked (depending on the order). We should prefer entries with extended ID available. Signed-off-by: Rafał Miłecki <zajec5@gmail.com> Cc: Bean Huo <beanhuo@micron.com> --- drivers/mtd/spi-nor/spi-nor.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)