From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: dedekind1@gmail.com, Richard Weinberger <richard@nod.at>,
adrian.hunter@intel.com, Heinz.Egger@linutronix.de,
shmulik.ladkani@gmail.com, tglx@linutronix.de,
tim.bird@am.sony.com
Subject: [PATCH 03/23] UBI: Fastmap: Fix find_fastmap() logic.
Date: Fri, 1 Jun 2012 17:16:24 +0200 [thread overview]
Message-ID: <1338563804-85990-4-git-send-email-richard@nod.at> (raw)
In-Reply-To: <1338563804-85990-1-git-send-email-richard@nod.at>
To grantee that we always use the newest fastmap we have to find
the fastmap super block with the highest sqnum.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/fastmap.c | 62 ++++++++++++++------------------------------
1 files changed, 20 insertions(+), 42 deletions(-)
diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index 75e067b..2326e5a 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -595,58 +595,45 @@ fail:
* ubi_find_fastmap - searches the first UBI_FM_MAX_START PEBs for the
* fastmap super block.
* @ubi: UBI device object
+ * @fm_start: Pointer where the fastmap suber block PEB number will be stored.
*
- * TODO: clearly document return codes
+ * Returns:
+ * - 0 on success: (fm_start contains suber block PEB number)
+ * - < 0 on failure (fm_start is -1)
*/
static int ubi_find_fastmap(struct ubi_device *ubi, int *fm_start)
{
int i, ret;
struct ubi_vid_hdr *vhdr;
+ unsigned long long max_sqnum = 0, sqnum;
vhdr = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
if (!vhdr)
return -ENOMEM;
+ *fm_start = -1;
for (i = 0; i < UBI_FM_MAX_START; i++) {
ret = ubi_io_read_vid_hdr(ubi, i, vhdr, 0);
if (ret < 0)
- break;
+ goto out;
else if (ret > 0)
continue;
if (be32_to_cpu(vhdr->vol_id) == UBI_FM_SB_VOLUME_ID) {
- *fm_start = i;
- /* TODO: fix globally: all UBI prints:
- * a) do not need the '\n' at the end
- * b) start with a small letter, because the macros
- * add several prefixes.
- */
- dbg_bld("Found fastmap super block at PEB %i\n", i);
- ret = 0;
+ sqnum = be64_to_cpu(vhdr->sqnum);
+ dbg_bld("found a fastmap super block at PEB %i sqnum: %llu", i, sqnum);
- break;
+ if (sqnum > max_sqnum) {
+ max_sqnum = sqnum;
+ *fm_start = i;
+ }
}
}
+ if (*fm_start > -1)
+ ret = 0;
+out:
ubi_free_vid_hdr(ubi, vhdr);
-
- /* TODO: we can return:
- * < 0 - error
- * 0 - fastmap found
- * 0 - also if we did not find fastmap and the last
- * 'ubi_io_read_vid_hdr()' call returned 0. This was not
- * tested with volumes which do not contain fastmap? We need to
- * test this - we need to have a testcase for this in mtd-utils. I
- * can create a branch there and we should agree on which tests are
- * run before anything goes into the git repo.
- * > 0 - ignore?
- *
- * Please, make it instead:
- * return 0 - no errors
- * return < 0 - error
- * If FM not found, fm_start = -1
- * If FM found, fm_start is set properly
- */
return ret;
}
@@ -668,19 +655,10 @@ int ubi_scan_fastmap(struct ubi_device *ubi, struct ubi_attach_info **ai)
unsigned long long sqnum = 0;
ret = ubi_find_fastmap(ubi, &sb_pnum);
- if (ret) {
- if (ret > 0)
- ret = UBI_NO_FASTMAP;
-
- goto out;
- }
- /* TODO: then this will be:
- * if (ret)
- * return ret;
- * if (sb_pnum == -1)
- * return UBI_NO_FASTMAP;
- *
- * Much better, I think */
+ if (ret)
+ return ret;
+ if (sb_pnum == -1)
+ return UBI_NO_FASTMAP;
fmsb = kmalloc(sizeof(*fmsb), GFP_KERNEL);
if (!fmsb) {
--
1.7.6.5
next prev parent reply other threads:[~2012-06-01 15:17 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-01 15:16 UBI: Fastmap updates (v7+) Richard Weinberger
2012-06-01 15:16 ` [PATCH 01/23] UBI: Fastmap: Fix EC overflow calculation Richard Weinberger
2012-06-01 15:16 ` [PATCH 02/23] UBI: Fastmap: Introduce fm_mutex Richard Weinberger
2012-06-01 15:16 ` Richard Weinberger [this message]
2012-06-01 15:16 ` [PATCH 04/23] UBI: Fastmap: Write a fastmap also at detaching Richard Weinberger
2012-06-01 15:16 ` [PATCH 05/23] UBI: Fastmap: Fix memory corruption Richard Weinberger
2012-06-01 15:16 ` [PATCH 06/23] UBI: Fastmap: Serialize ubi_wl_get_peb() Richard Weinberger
2012-06-01 15:16 ` [PATCH 07/23] UBI: Fastmap: Simplify ubi_wl_put_fm_peb() logic Richard Weinberger
2012-06-01 15:16 ` [PATCH 08/23] UBI: Fastmap: make ubi_is_fm_block() static Richard Weinberger
2012-06-01 15:16 ` [PATCH 09/23] UBI: Fastmap: Remove ubi->old_fm logic Richard Weinberger
2012-06-01 15:16 ` [PATCH 10/23] UBI: Fastmap: Allocate and free ubi_attach_info in ubi_attach() Richard Weinberger
2012-06-01 15:16 ` [PATCH 11/23] UBI: Fastmap: Fix messages Richard Weinberger
2012-06-01 15:16 ` [PATCH 12/23] ubi: fastmap: harmonize medium erase-counter seek algorithm Richard Weinberger
2012-06-01 15:16 ` [PATCH 13/23] UBI: Fastmap: Add comments to fastmap paremters Richard Weinberger
2012-06-01 15:16 ` [PATCH 14/23] UBI: Fastmap: Rename fastmap attributes Richard Weinberger
2012-06-01 15:16 ` [PATCH 15/23] UBI: Fastmap: Use reserved_pebs Richard Weinberger
2012-06-01 15:16 ` [PATCH 16/23] UBI: Fastmap: Store bad_peb_count in fastmap Richard Weinberger
2012-06-01 15:16 ` [PATCH 17/23] UBI: Fastmap: Add ubi_assert() Richard Weinberger
2012-06-01 15:16 ` [PATCH 18/23] UBI: Fastmap: Handle bitflipps correctly Richard Weinberger
2012-06-01 15:16 ` [PATCH 19/23] UBI: Fastmap: Handle protection queue correctly Richard Weinberger
2012-06-01 15:16 ` [PATCH 20/23] UBI: Fastmap: Write fastmap only at detach time if none is present Richard Weinberger
2012-06-01 15:16 ` [PATCH 21/23] UBI: Fastmap: Fix error message Richard Weinberger
2012-06-01 15:16 ` [PATCH 22/23] UBI: Fastmap: Address one of Artems TODOs Richard Weinberger
2012-06-01 15:16 ` [PATCH 23/23] UBI: Fastmap: Make checkpatch.pl happy (again) Richard Weinberger
2012-06-01 17:50 ` UBI: Fastmap updates (v7+) Artem Bityutskiy
2012-06-01 18:00 ` Richard Weinberger
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=1338563804-85990-4-git-send-email-richard@nod.at \
--to=richard@nod.at \
--cc=Heinz.Egger@linutronix.de \
--cc=adrian.hunter@intel.com \
--cc=dedekind1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=shmulik.ladkani@gmail.com \
--cc=tglx@linutronix.de \
--cc=tim.bird@am.sony.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;
as well as URLs for NNTP newsgroup(s).