All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: David Woodhouse <dwmw2@infradead.org>,
	linux-mtd@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	Ryan Harkin <ryan.harkin@linaro.org>,
	Liviu Dudau <liviu.dudau@arm.com>
Subject: Re: [PATCH 08/10] mtd: afs: factor footer parsing into the v1 part parsing
Date: Tue, 10 Nov 2015 19:17:03 -0800	[thread overview]
Message-ID: <20151111031703.GZ12143@google.com> (raw)
In-Reply-To: <1444914533-27782-9-git-send-email-linus.walleij@linaro.org>

Hi,

On Thu, Oct 15, 2015 at 03:08:51PM +0200, Linus Walleij wrote:
> This simplifies the code by factoring in the image footer
> parsing into the single function parsing the AFSv1 partitions.
> 
> Cc: Ryan Harkin <ryan.harkin@linaro.org>
> Cc: Liviu Dudau <liviu.dudau@arm.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/mtd/afs.c | 98 ++++++++++++++++++++++---------------------------------
>  1 file changed, 39 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
> index ace27f447abc..cdee8295d4c0 100644
> --- a/drivers/mtd/afs.c
> +++ b/drivers/mtd/afs.c
> @@ -89,63 +89,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off)
>  }
>  
>  static int
> -afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
> -		   u_int off, u_int mask)
> -{
> -	struct footer_v1 fs;
> -	u_int ptr = off + mtd->erasesize - sizeof(fs);
> -	size_t sz;
> -	int ret;
> -
> -	ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs);
> -	if (ret >= 0 && sz != sizeof(fs))
> -		ret = -EINVAL;
> -
> -	if (ret < 0) {
> -		printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
> -			ptr, ret);
> -		return ret;
> -	}
> -
> -	/*
> -	 * Does it contain the magic number?
> -	 */
> -	if (fs.signature != AFSV1_FOOTER_MAGIC)
> -		return 0;
> -
> -	/*
> -	 * Check the checksum.
> -	 */
> -	if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff)
> -		return 0;
> -
> -	/*
> -	 * Don't touch the SIB.
> -	 */
> -	if (fs.type == 2)
> -		return 0;
> -
> -	*iis_start = fs.image_info_base & mask;
> -	*img_start = fs.image_start & mask;
> -
> -	/*
> -	 * Check the image info base.  This can not
> -	 * be located after the footer structure.
> -	 */
> -	if (*iis_start >= ptr)
> -		return 0;
> -
> -	/*
> -	 * Check the start of this image.  The image
> -	 * data can not be located after this block.
> -	 */
> -	if (*img_start > off)
> -		return 0;
> -
> -	return 1;
> -}
> -
> -static int
>  afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr)
>  {
>  	size_t sz;
> @@ -184,6 +127,7 @@ afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr)
>  static int afs_parse_v1_partition(struct mtd_info *mtd,
>  				  u_int off, struct mtd_partition *part)
>  {
> +	struct footer_v1 fs;
>  	struct image_info_v1 iis;
>  	u_int mask;
>  	/*
> @@ -192,6 +136,8 @@ static int afs_parse_v1_partition(struct mtd_info *mtd,
>  	 */
>  	u_int uninitialized_var(iis_ptr);
>  	u_int uninitialized_var(img_ptr);
> +	u_int ptr;
> +	size_t sz;
>  	int ret;
>  
>  	/*
> @@ -200,9 +146,43 @@ static int afs_parse_v1_partition(struct mtd_info *mtd,
>  	 */
>  	mask = mtd->size - 1;
>  
> -	ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask);
> -	if (ret < 0)
> +	ptr = off + mtd->erasesize - sizeof(fs);
> +	ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs);
> +	if (ret >= 0 && sz != sizeof(fs))
> +		ret = -EINVAL;
> +	if (ret < 0) {
> +		printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
> +		       ptr, ret);
>  		return ret;
> +	}
> +	/*
> +	 * Check the checksum.
> +	 */
> +	if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff)
> +		return -EINVAL;

^^ This was modified. See my other comments about it.

Brian

> +
> +	/*
> +	 * Hide the SIB (System Information Block)
> +	 */
> +	if (fs.type == 2)
> +		return 0;
> +
> +	iis_ptr = fs.image_info_base & mask;
> +	img_ptr = fs.image_start & mask;
> +
> +	/*
> +	 * Check the image info base.  This can not
> +	 * be located after the footer structure.
> +	 */
> +	if (iis_ptr >= ptr)
> +		return 0;
> +
> +	/*
> +	 * Check the start of this image.  The image
> +	 * data can not be located after this block.
> +	 */
> +	if (img_ptr > off)
> +		return 0;
>  
>  	/* Read the image info block */
>  	ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
> -- 
> 2.4.3
> 

WARNING: multiple messages have this Message-ID (diff)
From: computersforpeace@gmail.com (Brian Norris)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 08/10] mtd: afs: factor footer parsing into the v1 part parsing
Date: Tue, 10 Nov 2015 19:17:03 -0800	[thread overview]
Message-ID: <20151111031703.GZ12143@google.com> (raw)
In-Reply-To: <1444914533-27782-9-git-send-email-linus.walleij@linaro.org>

Hi,

On Thu, Oct 15, 2015 at 03:08:51PM +0200, Linus Walleij wrote:
> This simplifies the code by factoring in the image footer
> parsing into the single function parsing the AFSv1 partitions.
> 
> Cc: Ryan Harkin <ryan.harkin@linaro.org>
> Cc: Liviu Dudau <liviu.dudau@arm.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  drivers/mtd/afs.c | 98 ++++++++++++++++++++++---------------------------------
>  1 file changed, 39 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
> index ace27f447abc..cdee8295d4c0 100644
> --- a/drivers/mtd/afs.c
> +++ b/drivers/mtd/afs.c
> @@ -89,63 +89,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off)
>  }
>  
>  static int
> -afs_read_footer_v1(struct mtd_info *mtd, u_int *img_start, u_int *iis_start,
> -		   u_int off, u_int mask)
> -{
> -	struct footer_v1 fs;
> -	u_int ptr = off + mtd->erasesize - sizeof(fs);
> -	size_t sz;
> -	int ret;
> -
> -	ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs);
> -	if (ret >= 0 && sz != sizeof(fs))
> -		ret = -EINVAL;
> -
> -	if (ret < 0) {
> -		printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
> -			ptr, ret);
> -		return ret;
> -	}
> -
> -	/*
> -	 * Does it contain the magic number?
> -	 */
> -	if (fs.signature != AFSV1_FOOTER_MAGIC)
> -		return 0;
> -
> -	/*
> -	 * Check the checksum.
> -	 */
> -	if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff)
> -		return 0;
> -
> -	/*
> -	 * Don't touch the SIB.
> -	 */
> -	if (fs.type == 2)
> -		return 0;
> -
> -	*iis_start = fs.image_info_base & mask;
> -	*img_start = fs.image_start & mask;
> -
> -	/*
> -	 * Check the image info base.  This can not
> -	 * be located after the footer structure.
> -	 */
> -	if (*iis_start >= ptr)
> -		return 0;
> -
> -	/*
> -	 * Check the start of this image.  The image
> -	 * data can not be located after this block.
> -	 */
> -	if (*img_start > off)
> -		return 0;
> -
> -	return 1;
> -}
> -
> -static int
>  afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr)
>  {
>  	size_t sz;
> @@ -184,6 +127,7 @@ afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr)
>  static int afs_parse_v1_partition(struct mtd_info *mtd,
>  				  u_int off, struct mtd_partition *part)
>  {
> +	struct footer_v1 fs;
>  	struct image_info_v1 iis;
>  	u_int mask;
>  	/*
> @@ -192,6 +136,8 @@ static int afs_parse_v1_partition(struct mtd_info *mtd,
>  	 */
>  	u_int uninitialized_var(iis_ptr);
>  	u_int uninitialized_var(img_ptr);
> +	u_int ptr;
> +	size_t sz;
>  	int ret;
>  
>  	/*
> @@ -200,9 +146,43 @@ static int afs_parse_v1_partition(struct mtd_info *mtd,
>  	 */
>  	mask = mtd->size - 1;
>  
> -	ret = afs_read_footer_v1(mtd, &img_ptr, &iis_ptr, off, mask);
> -	if (ret < 0)
> +	ptr = off + mtd->erasesize - sizeof(fs);
> +	ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs);
> +	if (ret >= 0 && sz != sizeof(fs))
> +		ret = -EINVAL;
> +	if (ret < 0) {
> +		printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
> +		       ptr, ret);
>  		return ret;
> +	}
> +	/*
> +	 * Check the checksum.
> +	 */
> +	if (word_sum(&fs, sizeof(fs) / sizeof(u32)) != 0xffffffff)
> +		return -EINVAL;

^^ This was modified. See my other comments about it.

Brian

> +
> +	/*
> +	 * Hide the SIB (System Information Block)
> +	 */
> +	if (fs.type == 2)
> +		return 0;
> +
> +	iis_ptr = fs.image_info_base & mask;
> +	img_ptr = fs.image_start & mask;
> +
> +	/*
> +	 * Check the image info base.  This can not
> +	 * be located after the footer structure.
> +	 */
> +	if (iis_ptr >= ptr)
> +		return 0;
> +
> +	/*
> +	 * Check the start of this image.  The image
> +	 * data can not be located after this block.
> +	 */
> +	if (img_ptr > off)
> +		return 0;
>  
>  	/* Read the image info block */
>  	ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
> -- 
> 2.4.3
> 

  reply	other threads:[~2015-11-11  3:17 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-15 13:08 [PATCH 00/10] ARM MTD AFS v2 partition support Linus Walleij
2015-10-15 13:08 ` Linus Walleij
2015-10-15 13:08 ` [PATCH 01/10] mtd: afs: rename structs and functions for v1 Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-10-15 13:08 ` [PATCH 02/10] mtd: enable AFS selection for ARM64 Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-10-15 13:08 ` [PATCH 03/10] mtd: afs: break out v1 footer magic to a define Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-10-15 13:08 ` [PATCH 04/10] mtd: afs: refactor v1 partition parsing Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-10-15 13:08 ` [PATCH 05/10] mtd: afs: simplify " Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-11-11  2:28   ` Brian Norris
2015-11-11  2:28     ` Brian Norris
2015-10-15 13:08 ` [PATCH 06/10] mtd: afs: simplify partition detection Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-11-11  3:09   ` Brian Norris
2015-11-11  3:09     ` Brian Norris
2015-10-15 13:08 ` [PATCH 07/10] mtd: factor out v1 partition parsing Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-11-11  3:15   ` Brian Norris
2015-11-11  3:15     ` Brian Norris
2015-10-15 13:08 ` [PATCH 08/10] mtd: afs: factor footer parsing into the v1 part parsing Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-11-11  3:17   ` Brian Norris [this message]
2015-11-11  3:17     ` Brian Norris
2015-10-15 13:08 ` [PATCH 09/10] mtd: afs: factor the IIS read into partition parser Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-11-11 18:09   ` Brian Norris
2015-11-11 18:09     ` Brian Norris
2015-10-15 13:08 ` [PATCH 10/10] mtd: afs: add v2 partition parsing Linus Walleij
2015-10-15 13:08   ` Linus Walleij
2015-11-11  3:20   ` Brian Norris
2015-11-11  3:20     ` Brian Norris
2015-11-11 18:46   ` Brian Norris
2015-11-11 18:46     ` Brian Norris
2015-10-26 13:10 ` [PATCH 00/10] ARM MTD AFS v2 partition support Linus Walleij
2015-10-26 13:10   ` Linus Walleij
2015-11-11  2:15 ` Brian Norris
2015-11-11  2:15   ` Brian Norris
2015-11-11 15:13   ` Linus Walleij
2015-11-11 15:13     ` Linus Walleij
2015-11-11 18:01     ` Brian Norris
2015-11-11 18:01       ` 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=20151111031703.GZ12143@google.com \
    --to=computersforpeace@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=liviu.dudau@arm.com \
    --cc=ryan.harkin@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.