linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: Ben Shelton <ben.shelton@ni.com>
Cc: dmw2@infradead.org, linux-mtd@lists.infradead.org,
	linux-kernel@vger.kernel.org, Cai Zhiyong <caizhiyong@huawei.com>
Subject: Re: [PATCH] mtd: cmdlinepart: allow fill-up partition at any point
Date: Tue, 29 Sep 2015 12:55:39 -0700	[thread overview]
Message-ID: <20150929195539.GF31505@google.com> (raw)
In-Reply-To: <1431053861-32284-1-git-send-email-ben.shelton@ni.com>

Sorry for delay... a lot of things came on my plate, so things got
buried.

I fixed up a few conflicts locally with some of my patches, but I have a
few problems with your patch, so I'll have to request another revision.

On Thu, May 07, 2015 at 09:57:41PM -0500, Ben Shelton wrote:
> Currently, a fill-up partition (indicated by '-') must be the last
> partition, and no other partitions can go after it.  Change the
> cmdlinepart parsing code to allow a fill-up partition at any point.
> This is useful, for example, if you want to reserve a partition at the
> end of the flash where the bad block table will go.
> 
> Signed-off-by: Ben Shelton <ben.shelton@ni.com>

For one, I think we need a little update to the parser documentation
(i.e., code comments at the top) to show at least an example of this new
allowed syntax.

> ---
>  drivers/mtd/cmdlinepart.c | 33 ++++++++++++++++++++++++++-------
>  1 file changed, 26 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
> index c850300..2d0eda2 100644
> --- a/drivers/mtd/cmdlinepart.c
> +++ b/drivers/mtd/cmdlinepart.c
> @@ -97,6 +97,7 @@ static struct mtd_partition * newpart(char *s,
>  				      char **retptr,
>  				      int *num_parts,
>  				      int this_part,
> +				      int size_remaining_found,
>  				      unsigned char **extra_mem_ptr,
>  				      int extra_mem_size)
>  {
> @@ -110,9 +111,16 @@ static struct mtd_partition * newpart(char *s,
>  
>  	/* fetch the partition size */
>  	if (*s == '-') {
> +		if (size_remaining_found) {
> +			printk(KERN_ERR ERRP

Trivial: we can use pr_err() now (see l2-mtd.git).

> +			       "more than one '-' partition specified\n");
> +			return ERR_PTR(-EINVAL);
> +		}
> +
>  		/* assign all remaining space to this partition */
>  		size = SIZE_REMAINING;
>  		s++;
> +		size_remaining_found = 1;
>  	} else {
>  		size = memparse(s, &s);
>  		if (size < PAGE_SIZE) {
> @@ -169,13 +177,10 @@ static struct mtd_partition * newpart(char *s,
>  
>  	/* test if more partitions are following */
>  	if (*s == ',') {
> -		if (size == SIZE_REMAINING) {
> -			printk(KERN_ERR ERRP "no partitions allowed after a fill-up partition\n");
> -			return ERR_PTR(-EINVAL);
> -		}
>  		/* more partitions follow, parse them */
>  		parts = newpart(s + 1, &s, num_parts, this_part + 1,
> -				&extra_mem, extra_mem_size);
> +				size_remaining_found, &extra_mem,
> +				extra_mem_size);
>  		if (IS_ERR(parts))
>  			return parts;
>  	} else {
> @@ -252,6 +257,7 @@ static int mtdpart_setup_real(char *s)
>  				&s,		/* out: updated cmdline ptr */
>  				&num_parts,	/* out: number of parts */
>  				0,		/* first partition */
> +				0,		/* size_remaining not found */
>  				(unsigned char**)&this_mtd, /* out: extra mem */
>  				mtd_id_len + 1 + sizeof(*this_mtd) +
>  				sizeof(void*)-1 /*alignment*/);
> @@ -313,6 +319,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
>  	int i, err;
>  	struct cmdline_mtd_partition *part;
>  	const char *mtd_id = master->name;
> +	int sr_part_num = -1;
>  
>  	/* parse command line */
>  	if (!cmdline_parsed) {
> @@ -339,8 +346,10 @@ static int parse_cmdline_partitions(struct mtd_info *master,
>  		else
>  			offset = part->parts[i].offset;
>  
> -		if (part->parts[i].size == SIZE_REMAINING)
> -			part->parts[i].size = master->size - offset;
> +		if (part->parts[i].size == SIZE_REMAINING) {
> +			sr_part_num = i;
> +			continue;
> +		}

Here, you are dropping this property for fill partitions:

  "if specified or truncated size is 0 the part is skipped"

Since the size is no longer computed in this loop, it will never match
the 'size == 0' check.

>  
>  		if (offset + part->parts[i].size > master->size) {
>  			printk(KERN_WARNING ERRP
> @@ -361,6 +370,16 @@ static int parse_cmdline_partitions(struct mtd_info *master,
>  		}
>  	}
>  
> +	/* if a partition was marked as SIZE_REMAINING */
> +	if (sr_part_num != -1) {
> +		/* fix up the size of the SIZE_REMAINING partition */
> +		part->parts[sr_part_num].size = master->size - offset;

The use of 'offset' doesn't look correct. At this point, 'offset' is the
address of the end of the last partition. That looks like you're still
sizing the fill partition to be only at the end of the flash, which is
not the point of this patch. Am I missing something?

> +
> +		/* fix up the offsets of the subsequent partitions */
> +		for (i = (sr_part_num + 1); i < part->num_parts; i++)
> +			part->parts[i].offset += part->parts[sr_part_num].size;

Is this a legal adjustment? Is it possible to have fixed address (not
OFFSET_CONTINUOUS) partitions after the fill partition? I see that would
actually make this kind of ambiguous. So maybe you need to specify this
in the documentation and check for it in the parsing -- see that once
size_remaining_found > 0, we don't allow any more partitions
'@<address'> (i.e., not OFFSET_CONTINUOUS).

> +	}
> +
>  	*pparts = kmemdup(part->parts, sizeof(*part->parts) * part->num_parts,
>  			  GFP_KERNEL);
>  	if (!*pparts)

I think this patch speaks to our need for unit tests... that way we can
clearly and definitively show pass/fail for any regressions.

This reminds me of Cai Zhiyong's attempts to unify this parser with the
new block/cmdline-parser, without getting any test results for the
variety of existing MTD use cases...

Brian

  reply	other threads:[~2015-09-29 19:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-08  2:57 [PATCH] mtd: cmdlinepart: allow fill-up partition at any point Ben Shelton
2015-09-29 19:55 ` Brian Norris [this message]
2015-09-29 20:00   ` Brian Norris
2015-09-29 20:18     ` Josh Cartwright
2015-09-29 20:28       ` Brian Norris

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=20150929195539.GF31505@google.com \
    --to=computersforpeace@gmail.com \
    --cc=ben.shelton@ni.com \
    --cc=caizhiyong@huawei.com \
    --cc=dmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).