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: <d8de86aa0331be697fbef33d5ab2c57a@walle.cc>
Date:   Thu, 14 Jul 2022 21:41:48 +0200
From:   Michael Walle <michael@...le.cc>
To:     Michal Suchanek <msuchanek@...e.de>
Cc:     linux-sunxi@...ts.linux.dev, Rob Herring <robh+dt@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
        Chen-Yu Tsai <wens@...e.org>,
        Jernej Skrabec <jernej.skrabec@...il.com>,
        Samuel Holland <samuel@...lland.org>,
        Tudor Ambarus <tudor.ambarus@...rochip.com>,
        Pratyush Yadav <p.yadav@...com>,
        Miquel Raynal <miquel.raynal@...tlin.com>,
        Richard Weinberger <richard@....at>,
        Vignesh Raghavendra <vigneshr@...com>,
        devicetree@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
        linux-kernel@...r.kernel.org, linux-mtd@...ts.infradead.org
Subject: Re: [PATCH 1/2] mtd: spi-nor: When a flash memory is missing do not
 report an error

Hi,

Am 2022-07-14 21:19, schrieb Michal Suchanek:
> It is normal that devices are designed with multiple types of storage,
> and only some types of storage are present.
> 
> The kernel can handle this situation gracefully for many types of
> storage devices such as mmc or ata but it reports and error when spi
> flash is not present.
> 
> Only print a notice that the storage device is missing when no response
> to the identify command is received.
> 
> Consider reply buffers with all bits set to the same value no response.

I'm not sure you can compare SPI with ATA and MMC. I'm just speaking of
DT now, but there, for ATA and MMC you just describe the controller and
it will auto-detect the connected storage. Whereas with SPI you describe
both the controller and the flash. So I'd argue that your hardware
description is wrong if it describes a flash which is not present.

> Signed-off-by: Michal Suchanek <msuchanek@...e.de>
> ---
>  drivers/mtd/spi-nor/core.c | 25 +++++++++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> index 502967c76c5f..6bab540171a4 100644
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
> @@ -1652,6 +1652,24 @@ static const struct flash_info
> *spi_nor_match_id(struct spi_nor *nor,
>  	return NULL;
>  }
> 
> +static const bool buffer_uniform(const u8 *buffer, size_t length)
> +{
> +	bool all0;
> +	size_t i;
> +
> +	for (all0 = true, i = 0; i < length; i++)
> +		if (buffer[i] != 0) {
> +			all0 = false;
> +			break;
> +		}
> +	if (all0)
> +		return true;
> +	for (i = 0; i < length; i++)
> +		if (buffer[i] != 0xff)
> +			return false;
> +	return true;
> +}

That seems unnecessarily complex.
if (!memchr_inv(id, '\x00', SPI_NOR_MAX_ID_LEN) ||
     !memchr_inv(id, '\xff', SPI_NOR_MAX_ID_LEN))

should be the same.

-michael

> +
>  static const struct flash_info *spi_nor_detect(struct spi_nor *nor)
>  {
>  	const struct flash_info *info;
> @@ -1666,8 +1684,11 @@ static const struct flash_info
> *spi_nor_detect(struct spi_nor *nor)
> 
>  	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);
> +		if (buffer_uniform(id, SPI_NOR_MAX_ID_LEN))
> +			dev_info(nor->dev, "No flash memory detected.\n");
> +		else
> +			dev_err(nor->dev, "unrecognized JEDEC id bytes: %*ph\n",
> +				SPI_NOR_MAX_ID_LEN, id);
>  		return ERR_PTR(-ENODEV);
>  	}
>  	return info;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ