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 09/10] mtd: afs: factor the IIS read into partition parser
Date: Wed, 11 Nov 2015 10:09:01 -0800 [thread overview]
Message-ID: <20151111180901.GC12143@google.com> (raw)
In-Reply-To: <1444914533-27782-10-git-send-email-linus.walleij@linaro.org>
Hi Linus,
On Thu, Oct 15, 2015 at 03:08:52PM +0200, Linus Walleij wrote:
> Factor the IIS (Image Information Structure) reading into the
> partition parser, giving us a single, clean partition parser
> function.
>
> 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 | 59 +++++++++++++++++++------------------------------------
> 1 file changed, 20 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c
> index cdee8295d4c0..1ce6842c917c 100644
> --- a/drivers/mtd/afs.c
> +++ b/drivers/mtd/afs.c
> @@ -88,42 +88,6 @@ static bool afs_is_v1(struct mtd_info *mtd, u_int off)
> return (magic == AFSV1_FOOTER_MAGIC);
> }
>
> -static int
> -afs_read_iis_v1(struct mtd_info *mtd, struct image_info_v1 *iis, u_int ptr)
> -{
> - size_t sz;
> - int ret, i;
> -
> - memset(iis, 0, sizeof(*iis));
> - ret = mtd_read(mtd, ptr, sizeof(*iis), &sz, (u_char *)iis);
> - if (ret < 0)
> - goto failed;
> -
> - if (sz != sizeof(*iis)) {
> - ret = -EINVAL;
> - goto failed;
> - }
> -
> - ret = 0;
> -
> - /*
> - * Validate the name - it must be NUL terminated.
> - */
> - for (i = 0; i < sizeof(iis->name); i++)
> - if (iis->name[i] == '\0')
> - break;
> -
> - if (i < sizeof(iis->name))
> - ret = 1;
> -
> - return ret;
> -
> - failed:
> - printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
> - ptr, ret);
> - return ret;
> -}
> -
> static int afs_parse_v1_partition(struct mtd_info *mtd,
> u_int off, struct mtd_partition *part)
> {
> @@ -139,6 +103,7 @@ static int afs_parse_v1_partition(struct mtd_info *mtd,
> u_int ptr;
> size_t sz;
> int ret;
> + int i;
>
> /*
> * This is the address mask; we use this to mask off out of
> @@ -185,9 +150,25 @@ static int afs_parse_v1_partition(struct mtd_info *mtd,
> return 0;
>
> /* Read the image info block */
> - ret = afs_read_iis_v1(mtd, &iis, iis_ptr);
> - if (ret < 0)
> - return ret;
> + memset(&iis, 0, sizeof(iis));
> + ret = mtd_read(mtd, iis_ptr, sizeof(iis), &sz, (u_char *)&iis);
> + if (ret < 0) {
> + printk(KERN_ERR "AFS: mtd read failed at 0x%x: %d\n",
> + iis_ptr, ret);
> + return -EINVAL;
> + }
> +
> + if (sz != sizeof(iis))
> + return -EINVAL;
> +
> + /*
> + * Validate the name - it must be NUL terminated.
> + */
> + for (i = 0; i < sizeof(iis.name); i++)
> + if (iis.name[i] == '\0')
> + break;
> + if (i > sizeof(iis.name))
The above condition is not a correct refactoring. That should be an
inclusive comparison (i.e., i >= sizeof(iis.name)).
> + return -EINVAL;
>
> part->name = kstrdup(iis.name, GFP_KERNEL);
> if (!part->name)
Brian
next prev parent reply other threads:[~2015-11-11 18:09 UTC|newest]
Thread overview: 22+ 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 ` [PATCH 01/10] mtd: afs: rename structs and functions for v1 Linus Walleij
2015-10-15 13:08 ` [PATCH 02/10] mtd: enable AFS selection for ARM64 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 ` [PATCH 04/10] mtd: afs: refactor v1 partition parsing Linus Walleij
2015-10-15 13:08 ` [PATCH 05/10] mtd: afs: simplify " Linus Walleij
2015-11-11 2:28 ` Brian Norris
2015-10-15 13:08 ` [PATCH 06/10] mtd: afs: simplify partition detection Linus Walleij
2015-11-11 3:09 ` Brian Norris
2015-10-15 13:08 ` [PATCH 07/10] mtd: factor out v1 partition parsing Linus Walleij
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-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-11-11 18:09 ` Brian Norris [this message]
2015-10-15 13:08 ` [PATCH 10/10] mtd: afs: add v2 partition parsing Linus Walleij
2015-11-11 3:20 ` 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-11-11 2:15 ` Brian Norris
2015-11-11 15:13 ` Linus Walleij
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=20151111180901.GC12143@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 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).