Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: David Woodhouse <David.Woodhouse@intel.com>,
	Artem Bityutskiy <dedekind1@gmail.com>,
	Brian Norris <computersforpeace@gmail.com>,
	linux-mtd@lists.infradead.org
Cc: "Rafał Miłecki" <zajec5@gmail.com>, "Bean Huo" <beanhuo@micron.com>
Subject: [PATCH] mtd: spi-nor: prefer more specific entries from chips database
Date: Wed, 22 Oct 2014 09:33:43 +0200	[thread overview]
Message-ID: <1413963223-6365-1-git-send-email-zajec5@gmail.com> (raw)

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

             reply	other threads:[~2014-10-22  7:34 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-22  7:33 Rafał Miłecki [this message]
2014-11-06  7:02 ` [PATCH V2] mtd: spi-nor: prefer more specific entries from chips database 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)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1413963223-6365-1-git-send-email-zajec5@gmail.com \
    --to=zajec5@gmail.com \
    --cc=David.Woodhouse@intel.com \
    --cc=beanhuo@micron.com \
    --cc=computersforpeace@gmail.com \
    --cc=dedekind1@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox