From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752238AbcBEHfY (ORCPT ); Fri, 5 Feb 2016 02:35:24 -0500 Received: from down.free-electrons.com ([37.187.137.238]:49514 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751246AbcBEHfW (ORCPT ); Fri, 5 Feb 2016 02:35:22 -0500 Date: Fri, 5 Feb 2016 08:35:18 +0100 From: Boris Brezillon To: David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org Cc: Daniel Mack , Haojian Zhuang , Robert Jarzmik , Kukjin Kim , Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ralf Baechle , linux-mips@linux-mips.org, Josh Wu , Ezequiel Garcia , Maxime Ripard , Chen-Yu Tsai , linux-sunxi@googlegroups.com, Stefan Agner , Kyungmin Park , Greg Kroah-Hartman , devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, punnaiah choudary kalluri , Priit Laes Subject: Re: [PATCH v2 05/51] mtd: add mtd_ooblayout_xxx() helper functions Message-ID: <20160205083518.7b54e9a7@bbrezillon> In-Reply-To: <1454580434-32078-6-git-send-email-boris.brezillon@free-electrons.com> References: <1454580434-32078-1-git-send-email-boris.brezillon@free-electrons.com> <1454580434-32078-6-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.27; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 4 Feb 2016 11:06:28 +0100 Boris Brezillon 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 > --- > 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 [...] > + > +/** > + * mtd_ooblayout_count_bytes - count the number of bytes in a OOB category > + * @mtd: mtd info structure > + * @iter: category iterator > + * > + * Count the number of bytes in a given category. > + * > + * Returns a positive value on success, a negative error code otherwise. > + */ > +static int mtd_ooblayout_count_bytes(struct mtd_info *mtd, > + int (*iter)(struct mtd_info *, > + int section, > + struct mtd_oob_region *oobregion)) > +{ > + struct mtd_oob_region oobregion = { }; > + int section = 0, ret, nbytes = 0; > + > + while (1) { > + ret = iter(mtd, section, &oobregion); ^ section++ Oops, will fix that in next version. > + if (ret) { > + if (ret == -ERANGE) > + ret = nbytes; > + break; > + } > + > + nbytes += oobregion.length; > + } > + > + return ret; > +} -- Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com