Skip to content

Commit e159079

Browse files
mwallePratyush Yadav
authored andcommitted
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 <[email protected]> Reviewed-by: Pratyush Yadav <[email protected]> Signed-off-by: Pratyush Yadav <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2d95d13 commit e159079

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

drivers/mtd/spi-nor/core.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3298,32 +3298,28 @@ static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
32983298

32993299
if (name)
33003300
info = spi_nor_match_name(nor, name);
3301-
/* Try to auto-detect if chip name wasn't specified or not found */
3302-
if (!info)
3303-
return spi_nor_detect(nor);
3304-
33053301
/*
3306-
* If caller has specified name of flash model that can normally be
3307-
* detected using JEDEC, let's verify it.
3302+
* Auto-detect if chip name wasn't specified or not found, or the chip
3303+
* has an ID. If the chip supposedly has an ID, we also do an
3304+
* auto-detection to compare it later.
33083305
*/
3309-
if (name && info->id) {
3306+
if (!info || info->id) {
33103307
const struct flash_info *jinfo;
33113308

33123309
jinfo = spi_nor_detect(nor);
3313-
if (IS_ERR(jinfo)) {
3310+
if (IS_ERR(jinfo))
33143311
return jinfo;
3315-
} else if (jinfo != info) {
3316-
/*
3317-
* JEDEC knows better, so overwrite platform ID. We
3318-
* can't trust partitions any longer, but we'll let
3319-
* mtd apply them anyway, since some partitions may be
3320-
* marked read-only, and we don't want to loose that
3321-
* information, even if it's not 100% accurate.
3322-
*/
3312+
3313+
/*
3314+
* If caller has specified name of flash model that can normally
3315+
* be detected using JEDEC, let's verify it.
3316+
*/
3317+
if (info && jinfo != info)
33233318
dev_warn(nor->dev, "found %s, expected %s\n",
33243319
jinfo->name, info->name);
3325-
info = jinfo;
3326-
}
3320+
3321+
/* If info was set before, JEDEC knows better. */
3322+
info = jinfo;
33273323
}
33283324

33293325
return info;

0 commit comments

Comments
 (0)