Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: spi-nor: prefer more specific entries from chips database
@ 2014-10-22  7:33 Rafał Miłecki
  2014-11-06  7:02 ` [PATCH V2] " Rafał Miłecki
  0 siblings, 1 reply; 6+ messages in thread
From: Rafał Miłecki @ 2014-10-22  7:33 UTC (permalink / raw)
  To: David Woodhouse, Artem Bityutskiy, Brian Norris, linux-mtd
  Cc: Rafał Miłecki, Bean Huo

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(-)

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-07  2:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-22  7:33 [PATCH] mtd: spi-nor: prefer more specific entries from chips database Rafał Miłecki
2014-11-06  7:02 ` [PATCH V2] " Rafał Miłecki
2014-11-07  1:21   ` Huang Shijie
2014-11-07  1:49     ` Bean Huo 霍斌斌 (beanhuo)
2014-11-07  2:06       ` Huang Shijie
2014-11-07  2:26         ` Bean Huo 霍斌斌 (beanhuo)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox