[PATCH] mtd: nand: warn if hamming layout is used with too large ECC

Boris Brezillon boris.brezillon at bootlin.com
Fri Feb 9 00:50:27 PST 2018


On Fri,  9 Feb 2018 00:33:05 +0100
Stefan Agner <stefan at agner.ch> wrote:

> Warn in case a driver uses too large ECC with hamming layout.
> This is especially helpful since hamming layout is the default
> layout when using hardware ECC and no specific OOB layout is
> specified.
> 
> Signed-off-by: Stefan Agner <stefan at agner.ch>
> ---
>  drivers/mtd/nand/nand_base.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index 96c97588e1ba..2f3f43d0e288 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -197,6 +197,8 @@ static int nand_ooblayout_free_lp_hamming(struct mtd_info *mtd, int section,
>  		return -EINVAL;
>  	}
>  
> +	WARN_ON(mtd->oobsize - ecc_offset < ecc->total);
> +

Did you hit this problem? Anyway, if there's a case where the number of
ECC bytes does not fit in the space reserved for ECC, there's a bug
before this point, and this should be checked at init/probe time.

>  	if (section == 0) {
>  		oobregion->offset = 2;
>  		oobregion->length = ecc_offset - 2;



-- 
Boris Brezillon, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
http://bootlin.com



More information about the linux-mtd mailing list