From: Rob Herring <robherring2@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V3 2/8] disk: fix get_device_and_partition() bootable search
Date: Tue, 18 Sep 2012 20:18:52 -0500 [thread overview]
Message-ID: <50591D7C.7070200@gmail.com> (raw)
In-Reply-To: <1348007874-20466-3-git-send-email-swarren@wwwdotorg.org>
On 09/18/2012 05:37 PM, Stephen Warren wrote:
> From: Stephen Warren <swarren@nvidia.com>
>
> The existing get_device_and_partition() bootable search loop attempts
> to save the current best known partition in variable best_part. However,
> it's actually just saving a copy of the (static) "info" variable, and
> hence ends up not doing anything much useful if no bootable partition
> is found. Fix this by reworking the loop to:
>
> a) When reading information about a partition, always read into the
> caller-supplied buffer; that way, if we find a bootable partition,
> there's no need to copy any information.
> b) Save the first known valid partition's structure content rather than
> pointer in the search loop, and restore the structure content rather
> than the pointer when the loop exits.
>
> Signed-off-by: Stephen Warren <swarren@nvidia.com>
> ---
> v3: New patch.
You might as well squash these into my original commits.
Rob
> ---
> disk/part.c | 38 +++++++++++++++++++++++++++++---------
> 1 files changed, 29 insertions(+), 9 deletions(-)
>
> diff --git a/disk/part.c b/disk/part.c
> index 6caf6d2..277a243 100644
> --- a/disk/part.c
> +++ b/disk/part.c
> @@ -447,7 +447,7 @@ int get_device_and_partition(const char *ifname, const char *dev_str,
> int p;
> int part = 0;
> char *part_str;
> - disk_partition_t *best_part = NULL;
> + disk_partition_t tmpinfo;
>
> if (dev_str)
> dev = simple_strtoul(dev_str, &ep, 16);
> @@ -483,24 +483,44 @@ int get_device_and_partition(const char *ifname, const char *dev_str,
> part = (int)simple_strtoul(++part_str, NULL, 16);
> ret = get_partition_info(desc, part, info);
> } else {
> - /* find the first bootable partition. If none are bootable,
> - * fall back to the first valid partition */
> + /*
> + * Find the first bootable partition.
> + * If none are bootable, fall back to the first valid partition.
> + */
> for (p = 1; p <= MAX_SEARCH_PARTITIONS; p++) {
> - ret = get_partition_info(desc, p, info);
> + ret = get_partition_info(*dev_desc, p, info);
> if (ret)
> continue;
>
> - if (!best_part || info->bootable) {
> - best_part = info;
> + /*
> + * First valid partition, or new better partition?
> + * If so, save partition ID.
> + */
> + if (!part || info->bootable)
> part = p;
> - }
>
> + /* Best possible partition? Stop searching. */
> if (info->bootable)
> break;
> +
> + /*
> + * We now need to search further for best possible.
> + * If we what we just queried was the best so far,
> + * save the info since we over-write it next loop.
> + */
> + if (part == p)
> + tmpinfo = *info;
> }
> - info = best_part;
> - if (part)
> + /* If we found any acceptable partition */
> + if (part) {
> + /*
> + * If we searched all possible partition IDs,
> + * return the first valid partition we found.
> + */
> + if (p == MAX_SEARCH_PARTITIONS + 1)
> + *info = tmpinfo;
> ret = 0;
> + }
> }
> if (ret) {
> printf("** Invalid partition %d, use `dev[:part]' **\n", part);
>
next prev parent reply other threads:[~2012-09-19 1:18 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-18 22:37 [U-Boot] [PATCH V3 0/8] disk: "part" command and dependencies Stephen Warren
2012-09-18 22:37 ` [U-Boot] [PATCH V3 1/8] disk: parameterize get_device_and_partition's loop count Stephen Warren
2012-09-18 22:37 ` [U-Boot] [PATCH V3 2/8] disk: fix get_device_and_partition() bootable search Stephen Warren
2012-09-19 1:18 ` Rob Herring [this message]
2012-09-18 22:37 ` [U-Boot] [PATCH V3 3/8] disk: introduce get_device() Stephen Warren
2012-09-19 1:21 ` Rob Herring
2012-09-19 1:25 ` Rob Herring
2012-09-19 17:18 ` Stephen Warren
2012-09-19 18:17 ` Tom Rini
2012-09-21 12:53 ` Rob Herring
2012-09-21 16:09 ` Stephen Warren
2012-09-18 22:37 ` [U-Boot] [PATCH V3 4/8] disk: get_device_and_partition() enhancements Stephen Warren
2012-09-18 22:37 ` [U-Boot] [PATCH V3 5/8] disk: part_efi: range-check partition number Stephen Warren
2012-09-18 22:37 ` [U-Boot] [PATCH V3 6/8] disk: part_efi: parse and store partition UUID Stephen Warren
2012-09-18 22:37 ` [U-Boot] [PATCH V3 7/8] disk: part_msdos: " Stephen Warren
2012-09-18 22:37 ` [U-Boot] [PATCH V3 8/8] cmd_part: add partition-related command Stephen Warren
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=50591D7C.7070200@gmail.com \
--to=robherring2@gmail.com \
--cc=u-boot@lists.denx.de \
/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.