lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f270ae65e7bf42b6aa8521c6a0db4784@walle.cc>
Date:   Mon, 21 Mar 2022 23:15:36 +0100
From:   Michael Walle <michael@...le.cc>
To:     Tudor Ambarus <tudor.ambarus@...rochip.com>
Cc:     p.yadav@...com, miquel.raynal@...tlin.com, richard@....at,
        vigneshr@...com, linux-mtd@...ts.infradead.org,
        linux-kernel@...r.kernel.org, nicolas.ferre@...rochip.com
Subject: Re: [PATCH v2 2/8] mtd: spi-nor: Introduce spi_nor_match_id()

Am 2022-02-28 12:17, schrieb Tudor Ambarus:
> Similar to spi_nor_match_name() extend the search of flash_info through
> all the manufacturers, this time doing the match by ID. There's no 
> reason
> to limit the search per manufacturer yet, do it globally, search the 
> flash
> in all the parts of all manufacturers in a single method.
> 
> Signed-off-by: Tudor Ambarus <tudor.ambarus@...rochip.com>

Reviewed-by: Michael Walle <michael@...le.cc>

> ---
>  drivers/mtd/spi-nor/core.c | 40 ++++++++++++++++++--------------------
>  1 file changed, 19 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index f3c359d03163..f87cb7d3daab 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1629,16 +1629,21 @@ static const struct spi_nor_manufacturer
> *manufacturers[] = {
>  	&spi_nor_xmc,
>  };
> 
> -static const struct flash_info *
> -spi_nor_search_part_by_id(const struct flash_info *parts, unsigned int 
> nparts,
> -			  const u8 *id)
> +static const struct flash_info *spi_nor_match_id(struct spi_nor *nor,
> +						 const u8 *id)
>  {
> -	unsigned int i;
> +	const struct flash_info *part;
> +	unsigned int i, j;
> 
> -	for (i = 0; i < nparts; i++) {
> -		if (parts[i].id_len &&
> -		    !memcmp(parts[i].id, id, parts[i].id_len))
> -			return &parts[i];
> +	for (i = 0; i < ARRAY_SIZE(manufacturers); i++) {
> +		for (j = 0; j < manufacturers[i]->nparts; j++) {
> +			part = &manufacturers[i]->parts[j];
> +			if (part->id_len &&
> +			    !memcmp(part->id, id, part->id_len)) {
> +				nor->manufacturer = manufacturers[i];
> +				return part;
> +			}
> +		}
>  	}
> 
>  	return NULL;
> @@ -1648,7 +1653,6 @@ static const struct flash_info
> *spi_nor_read_id(struct spi_nor *nor)
>  {
>  	const struct flash_info *info;
>  	u8 *id = nor->bouncebuf;
> -	unsigned int i;
>  	int ret;
> 
>  	if (nor->spimem) {
> @@ -1668,19 +1672,13 @@ static const struct flash_info
> *spi_nor_read_id(struct spi_nor *nor)
>  		return ERR_PTR(ret);
>  	}
> 
> -	for (i = 0; i < ARRAY_SIZE(manufacturers); i++) {
> -		info = spi_nor_search_part_by_id(manufacturers[i]->parts,
> -						 manufacturers[i]->nparts,
> -						 id);
> -		if (info) {
> -			nor->manufacturer = manufacturers[i];
> -			return info;
> -		}
> +	info = spi_nor_match_id(nor, id);
> +	if (!info) {
> +		dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
> +			SPI_NOR_MAX_ID_LEN, id);
> +		return ERR_PTR(-ENODEV);
>  	}
> -
> -	dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
> -		SPI_NOR_MAX_ID_LEN, id);
> -	return ERR_PTR(-ENODEV);
> +	return info;
>  }
> 
>  static int spi_nor_read(struct mtd_info *mtd, loff_t from, size_t len,

-- 
-michael

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ