Message ID | 20240419141249.609534-6-mwalle@kernel.org |
---|---|
State | New |
Headers | show |
Series | mtd: spi-nor: spring cleaning | expand |
On 4/19/24 15:12, Michael Walle wrote: > 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> > --- > drivers/mtd/spi-nor/core.c | 45 ++++++++++++++++++-------------------- > 1 file changed, 21 insertions(+), 24 deletions(-) > > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c > index 4e2ae6642d4c..8e4ae1317870 100644 > --- a/drivers/mtd/spi-nor/core.c > +++ b/drivers/mtd/spi-nor/core.c > @@ -3294,39 +3294,36 @@ static const struct flash_info *spi_nor_match_name(struct spi_nor *nor, > static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, > const char *name) > { > - const struct flash_info *info = NULL; > + const struct flash_info *jinfo = NULL, *info = NULL; > > 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) { > - const struct flash_info *jinfo; > - > + if (!info || info->id) { > jinfo = spi_nor_detect(nor); > - if (IS_ERR(jinfo)) { > + if (IS_ERR(jinfo)) > return jinfo; > - } else if (jinfo != info) { you can remove else if with 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. > - */ > - dev_warn(nor->dev, "found %s, expected %s\n", > - jinfo->name, info->name); keep the warning where it was > - info = jinfo; move this so that it belongs to if (!info || info->id) > - } > } > and then return info. Does it work? if (name) info = spi_nor_match_name(nor, name); if (!info || info->id) { jinfo = spi_nor_detect(nor); if (IS_ERR(jinfo)) return jinfo; if (jinfo != info) dev_warn((); info = jinfo; } return info; > - return info; > + /* > + * If caller has specified name of flash model that can normally be > + * detected using JEDEC, let's verify it. > + */ > + if (info && jinfo && jinfo != info)> + dev_warn(nor->dev, "found %s, expected %s\n", > + jinfo->name, info->name); > + > + /* > + * 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. > + */ > + return jinfo ?: info;
Hi, > if (name) > info = spi_nor_match_name(nor, name); > > if (!info || info->id) { > jinfo = spi_nor_detect(nor); > if (IS_ERR(jinfo)) > return jinfo; > > if (jinfo != info) info could be NULL here. So "info &&", apart from that looks good. > dev_warn((); > info = jinfo; > } Pratyush, should I'll drop your Rb tag then. -michael
On 4/22/24 10:53, Michael Walle wrote: > Hi, > >> if (name) >> info = spi_nor_match_name(nor, name); >> >> if (!info || info->id) { here >> jinfo = spi_nor_detect(nor); >> if (IS_ERR(jinfo)) >> return jinfo; >> >> if (jinfo != info) > > info could be NULL here. So "info &&", apart from that looks good. it can't be NULL, the parent if indicated above assures info isn't NULL > >> dev_warn((); >> info = jinfo; >> } > > Pratyush, should I'll drop your Rb tag then. > > -michael
On 4/22/24 11:12, Tudor Ambarus wrote: > > > On 4/22/24 10:53, Michael Walle wrote: >> Hi, >> >>> if (name) >>> info = spi_nor_match_name(nor, name); >>> >>> if (!info || info->id) { > > here > >>> jinfo = spi_nor_detect(nor); >>> if (IS_ERR(jinfo)) >>> return jinfo; >>> >>> if (jinfo != info) >> >> info could be NULL here. So "info &&", apart from that looks good. > > it can't be NULL, the parent if indicated above assures info isn't NULL ah, I read it wrong it's if (!info), you're right! > >> >>> dev_warn((); >>> info = jinfo; >>> } >> >> Pratyush, should I'll drop your Rb tag then. >> >> -michael
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 4e2ae6642d4c..8e4ae1317870 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -3294,39 +3294,36 @@ static const struct flash_info *spi_nor_match_name(struct spi_nor *nor, static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, const char *name) { - const struct flash_info *info = NULL; + const struct flash_info *jinfo = NULL, *info = NULL; 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) { - const struct flash_info *jinfo; - + if (!info || info->id) { 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. - */ - dev_warn(nor->dev, "found %s, expected %s\n", - jinfo->name, info->name); - info = jinfo; - } } - return info; + /* + * If caller has specified name of flash model that can normally be + * detected using JEDEC, let's verify it. + */ + if (info && jinfo && jinfo != info) + dev_warn(nor->dev, "found %s, expected %s\n", + jinfo->name, info->name); + + /* + * 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. + */ + return jinfo ?: info; } static u32