[PATCH] mtd: spi-nor: prefer more specific entries from chips database

Rafał Miłecki zajec5 at gmail.com
Wed Oct 22 00:33:43 PDT 2014


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 at gmail.com>
Cc: Bean Huo <beanhuo at micron.com>
---
 drivers/mtd/spi-nor/spi-nor.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index c51ee52..727ec3c 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -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);
 }
-- 
1.8.4.5




More information about the linux-mtd mailing list