[PATCH 2/3] mtd: untangle error codes and number of partitions
Boris Brezillon
boris.brezillon at free-electrons.com
Mon Nov 30 12:56:06 EST 2015
On Thu, 19 Nov 2015 19:26:36 -0800
Brian Norris <computersforpeace at gmail.com> wrote:
> We're going to need to know how many partitions were registered, so
> let's disentangle the 'ret' and 'nr_parts' variables, so that nr_parts
> always represents the number of partitions we're registering.
>
> Signed-off-by: Brian Norris <computersforpeace at gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon at free-electrons.com>
> ---
> drivers/mtd/mtdcore.c | 10 ++++++----
> 1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index 62f83b050978..c8d54948bbc1 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -592,23 +592,25 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
> struct mtd_partition *real_parts = NULL;
>
> ret = parse_mtd_partitions(mtd, types, &real_parts, parser_data);
> - if (ret <= 0 && nr_parts && parts) {
> + if (ret > 0) {
> + nr_parts = ret;
> + } else if (ret <= 0 && nr_parts && parts) {
> real_parts = kmemdup(parts, sizeof(*parts) * nr_parts,
> GFP_KERNEL);
> if (!real_parts)
> ret = -ENOMEM;
> else
> - ret = nr_parts;
> + ret = 0;
> }
> /* Didn't come up with either parsed OR fallback partitions */
> if (ret < 0) {
> pr_info("mtd: failed to find partitions; one or more parsers reports errors (%d)\n",
> ret);
> /* Don't abort on errors; we can still use unpartitioned MTD */
> - ret = 0;
> + nr_parts = 0;
> }
>
> - ret = mtd_add_device_partitions(mtd, real_parts, ret);
> + ret = mtd_add_device_partitions(mtd, real_parts, nr_parts);
> if (ret)
> goto out;
>
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
More information about the linux-mtd
mailing list