public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: "Rafał Miłecki" <zajec5@gmail.com>
Cc: "Brian Norris" <computersforpeace@gmail.com>,
	"David Woodhouse" <dwmw2@infradead.org>,
	"Marek Vasut" <marek.vasut@gmail.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Cyrille Pitchen" <cyrille.pitchen@wedev4u.fr>,
	linux-mtd@lists.infradead.org,
	"Jonas Gorski" <jonas.gorski@gmail.com>,
	"Rafał Miłecki" <rafal@milecki.pl>
Subject: Re: [PATCH 2/2] mtd: get rid of the mtd_add_device_partitions function
Date: Fri, 12 Jan 2018 16:11:31 +0100	[thread overview]
Message-ID: <20180112161131.3cae7841@bbrezillon> (raw)
In-Reply-To: <20180112144034.6655-3-zajec5@gmail.com>

On Fri, 12 Jan 2018 15:40:34 +0100
Rafał Miłecki <zajec5@gmail.com> wrote:

> From: Rafał Miłecki <rafal@milecki.pl>
> 
> This simplifies code a bit by:
> 1) Avoiding an extra (tiny) function
> 2) Checking for amount of parsed (found) partitions just once
> 3) Avoiding clearing/filling struct mtd_partitions manually
> 
> With this commit a proper functions are called directly from the
> mtd_device_parse_register. It doesn't need to use minor tricks like
> memsetting struct to 0 to trigger an expected mtd_add_device_partitions
> behavior.
> 
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
> ---
>  drivers/mtd/mtdcore.c | 29 +++++++----------------------
>  1 file changed, 7 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index f6460862e2ad..0a414750bc8b 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -636,21 +636,6 @@ int del_mtd_device(struct mtd_info *mtd)
>  	return ret;
>  }
>  
> -static int mtd_add_device_partitions(struct mtd_info *mtd,
> -				     struct mtd_partitions *parts)
> -{
> -	const struct mtd_partition *real_parts = parts->parts;
> -	int nbparts = parts->nr_parts;
> -
> -	if (nbparts == 0 && !IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER))
> -		return add_mtd_device(mtd);
> -
> -	if (nbparts > 0)
> -		return add_mtd_partitions(mtd, real_parts, nbparts);
> -
> -	return 0;
> -}
> -
>  /*
>   * Set a few defaults based on the parent devices, if not provided by the
>   * driver
> @@ -717,19 +702,19 @@ int mtd_device_parse_register(struct mtd_info *mtd, const char * const *types,
>  	ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
>  	if ((ret < 0 || parsed.nr_parts == 0) && parts && nr_parts) {
>  		/* Fall back to driver-provided partitions */
> -		parsed = (struct mtd_partitions){
> -			.parts		= parts,
> -			.nr_parts	= nr_parts,
> -		};
> +		ret = add_mtd_partitions(mtd, parts, nr_parts);
>  	} else if (ret < 0) {
>  		/* Didn't come up with parsed OR fallback partitions */
>  		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 */
> -		memset(&parsed, 0, sizeof(parsed));
> +		if (!IS_ENABLED(CONFIG_MTD_PARTITIONED_MASTER))
> +			ret = add_mtd_device(mtd);
> +		else
> +			ret = 0;
> +	} else {
> +		ret = add_mtd_partitions(mtd, parsed.parts, parsed.nr_parts);
>  	}

How about:

	ret = parse_mtd_partitions(mtd, types, &parsed, parser_data);
	if (!ret && parsed.nr_parts) {
		parts = parsed.parts;
		nr_parts = parsed.nr_parts;
	}

	if (nr_parts)
		ret = add_mtd_partitions(mtd, parts, nr_parts);
	else if (!device_is_registered(&mtd->dev))
		ret = add_mtd_device(mtd);
	else
		ret = 0;

	...
> -
> -	ret = mtd_add_device_partitions(mtd, &parsed);
>  	if (ret)
>  		goto out;
>  

  reply	other threads:[~2018-01-12 15:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12 14:40 [PATCH 0/2] mtd: simplify mtd_device_parse_register code Rafał Miłecki
2018-01-12 14:40 ` [PATCH 1/2] mtd: move code adding master MTD out of mtd_add_device_partitions Rafał Miłecki
2018-01-12 15:01   ` Boris Brezillon
2018-01-15 10:58     ` Rafał Miłecki
2018-01-12 14:40 ` [PATCH 2/2] mtd: get rid of the mtd_add_device_partitions function Rafał Miłecki
2018-01-12 15:11   ` Boris Brezillon [this message]
2018-01-15 12:56     ` Rafał Miłecki
2018-01-15 13:22 ` [PATCH V2 0/2] mtd: simplify mtd_device_parse_register code Rafał Miłecki
2018-01-15 13:22   ` [PATCH V2 1/2] mtd: move code adding master MTD out of mtd_add_device_partitions Rafał Miłecki
2018-01-15 13:36     ` Boris Brezillon
2018-01-15 13:22   ` [PATCH V2 2/2] mtd: get rid of the mtd_add_device_partitions function Rafał Miłecki
2018-01-15 14:35   ` [PATCH V3 0/2] mtd: simplify mtd_device_parse_register code Rafał Miłecki
2018-01-15 14:35     ` [PATCH V3 1/2] mtd: move code adding master MTD out of mtd_add_device_partitions Rafał Miłecki
2018-01-15 14:35     ` [PATCH V3 2/2] mtd: get rid of the mtd_add_device_partitions function Rafał Miłecki
2018-01-15 22:45     ` [PATCH V4 0/2] mtd: simplify mtd_device_parse_register code Rafał Miłecki
2018-01-15 22:45       ` [PATCH V4 1/2] mtd: move code adding master MTD out of mtd_add_device_partitions Rafał Miłecki
2018-01-15 22:45       ` [PATCH V4 2/2] mtd: get rid of the mtd_add_device_partitions() Rafał Miłecki
     [not found]       ` <20180116154542.9767-1-zajec5@gmail.com>
2018-02-17  8:38         ` [PATCH V5 0/2] mtd: simplify mtd_device_parse_register() code Boris Brezillon
2018-02-18  7:50           ` Rafał Miłecki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180112161131.3cae7841@bbrezillon \
    --to=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@wedev4u.fr \
    --cc=dwmw2@infradead.org \
    --cc=jonas.gorski@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marek.vasut@gmail.com \
    --cc=rafal@milecki.pl \
    --cc=richard@nod.at \
    --cc=zajec5@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox