summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Walle <mwalle@kernel.org>2024-06-03 15:40:55 +0200
committerPratyush Yadav <pratyush@kernel.org>2024-06-18 11:42:19 +0200
commite159079a8be0222cf95909ed35eace0d6b2d12bf (patch)
tree39b4359fee6d2a302442a6e2c1cb06821d7cd737
parent2d95d13248446355fec961ef96703e552b75fe52 (diff)
downloadlinux-e159079a8be0222cf95909ed35eace0d6b2d12bf.tar.gz
linux-e159079a8be0222cf95909ed35eace0d6b2d12bf.tar.bz2
linux-e159079a8be0222cf95909ed35eace0d6b2d12bf.zip
mtd: spi-nor: simplify spi_nor_get_flash_info()
Rework spi_nor_get_flash_info() to make it look more straight forward and esp. don't return early. The latter is a preparation to check for deprecated flashes. Signed-off-by: Michael Walle <mwalle@kernel.org> Reviewed-by: Pratyush Yadav <pratyush@kernel.org> Signed-off-by: Pratyush Yadav <pratyush@kernel.org> Link: https://lore.kernel.org/r/20240603134055.1859863-1-mwalle@kernel.org
-rw-r--r--drivers/mtd/spi-nor/core.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 7128d45870d4..e0c4efc424f4 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -3298,32 +3298,28 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
if (name)
info = spi_nor_match_name(nor, name);
- /* Try to auto-detect if chip name wasn't specified or not found */
- if (!info)
- return spi_nor_detect(nor);
-
/*
- * If caller has specified name of flash model that can normally be
- * detected using JEDEC, let's verify it.
+ * Auto-detect if chip name wasn't specified or not found, or the chip
+ * has an ID. If the chip supposedly has an ID, we also do an
+ * auto-detection to compare it later.
*/
- if (name && info->id) {
+ if (!info || info->id) {
const struct flash_info *jinfo;
jinfo = spi_nor_detect(nor);
- if (IS_ERR(jinfo)) {
+ if (IS_ERR(jinfo))
return jinfo;
- } else if (jinfo != info) {
- /*
- * JEDEC knows better, so overwrite platform ID. We
- * can't trust partitions any longer, but we'll let
- * mtd apply them anyway, since some partitions may be
- * marked read-only, and we don't want to loose that
- * information, even if it's not 100% accurate.
- */
+
+ /*
+ * If caller has specified name of flash model that can normally
+ * be detected using JEDEC, let's verify it.
+ */
+ if (info && jinfo != info)
dev_warn(nor->dev, "found %s, expected %s\n",
jinfo->name, info->name);
- info = jinfo;
- }
+
+ /* If info was set before, JEDEC knows better. */
+ info = jinfo;
}
return info;