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: <20160205102710.39fa4244@bbrezillon>
Date:	Fri, 5 Feb 2016 10:27:10 +0100
From:	Boris Brezillon <boris.brezillon@...e-electrons.com>
To:	David Woodhouse <dwmw2@...radead.org>,
	Brian Norris <computersforpeace@...il.com>,
	linux-mtd@...ts.infradead.org
Cc:	Daniel Mack <daniel@...que.org>,
	Haojian Zhuang <haojian.zhuang@...il.com>,
	Robert Jarzmik <robert.jarzmik@...e.fr>,
	Kukjin Kim <kgene@...nel.org>,
	Krzysztof Kozlowski <k.kozlowski@...sung.com>,
	linux-samsung-soc@...r.kernel.org,
	linux-arm-kernel@...ts.infradead.org,
	Ralf Baechle <ralf@...ux-mips.org>, linux-mips@...ux-mips.org,
	Josh Wu <josh.wu@...el.com>,
	Ezequiel Garcia <ezequiel.garcia@...e-electrons.com>,
	Maxime Ripard <maxime.ripard@...e-electrons.com>,
	Chen-Yu Tsai <wens@...e.org>, linux-sunxi@...glegroups.com,
	Stefan Agner <stefan@...er.ch>,
	Kyungmin Park <kyungmin.park@...sung.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	devel@...verdev.osuosl.org, linux-kernel@...r.kernel.org,
	punnaiah choudary kalluri <punnaia@...inx.com>,
	Priit Laes <plaes@...es.org>
Subject: Re: [PATCH v2 05/51] mtd: add mtd_ooblayout_xxx() helper functions

On Thu,  4 Feb 2016 11:06:28 +0100
Boris Brezillon <boris.brezillon@...e-electrons.com> wrote:

> In order to make the ecclayout definition completely dynamic we need to
> rework the way the OOB layout are defined and iterated.
> 
> Create a few mtd_ooblayout_xxx() helpers to ease OOB bytes manipulation
> and hide ecclayout internals to their users.
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@...e-electrons.com>
> ---
>  drivers/mtd/mtdcore.c   | 401 ++++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/mtd/mtd.h |  33 ++++
>  2 files changed, 434 insertions(+)
> 
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index 3096251..14e46ca 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -997,6 +997,407 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
>  }
>  EXPORT_SYMBOL_GPL(mtd_read_oob);
>  
> +/**
> + * mtd_ooblayout_ecc - Get the OOB region definition of a specific ECC section
> + * @mtd: MTD device structure
> + * @section: ECC section. Depending on the layout you may have all the ECC
> + *	     bytes stored in a single contiguous section, or one section
> + *	     per ECC chunk (and sometime several sections for a single ECC
> + *	     ECC chunk)
> + * @oobecc: OOB region struct filled with the appropriate ECC position
> + *	    information
> + *
> + * This functions return ECC section information in the OOB area. I you want
> + * to get all the ECC bytes information, then you should call
> + * mtd_ooblayout_ecc(mtd, section++, oobecc) until it returns -ERANGE.
> + *
> + * Returns zero on success, a negative error code otherwise.
> + */
> +int mtd_ooblayout_ecc(struct mtd_info *mtd, int section,
> +		      struct mtd_oob_region *oobecc)
> +{
> +	int eccbyte = 0, cursection = 0, length = 0, eccpos = 0;
> +
> +	memset(oobecc, 0, sizeof(*oobecc));
> +
> +	if (!mtd || section < 0)
> +		return -EINVAL;
> +
> +	if (!mtd->ecclayout)
> +		return -ENOTSUPP;
> +
> +	if (mtd->ecclayout->eccbytes < 1)
> +		return -ERANGE;
> +
> +	/*
> +	 * This logic allows us to reuse the ->ecclayout information and
> +	 * expose them as ECC regions (as done for the OOB free regions).
> +	 *
> +	 * TODO: this should be dropped as soon as we get rid of the
> +	 * ->ecclayout field.
> +	 */
> +	for (eccbyte = 0; eccbyte < mtd->ecclayout->eccbytes; eccbyte++) {
> +		eccpos = mtd->ecclayout->eccpos[eccbyte];
> +
> +		if (eccbyte < mtd->ecclayout->eccbytes - 1) {
> +			int neccpos = mtd->ecclayout->eccpos[eccbyte + 1];
> +
> +			if (eccpos + 1 == neccpos) {
> +				length++;
> +				continue;
> +			}
> +		}
> +
> +		if (section == cursection)
> +			break;
> +
> +		length = 0;
> +		cursection++;
> +	}
> +
> +	if (cursection != section)

Should be
	if (cursection != section ||
	    eccbyte >= mtd->ecclayout->eccbytes)

Will fix that too.

> +		return -ERANGE;
> +
> +	oobecc->length = length + 1;
> +	oobecc->offset = eccpos - length;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(mtd_ooblayout_ecc);


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ