summaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-06-30 16:11:59 +0300
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2009-07-05 18:47:08 +0300
commitfe96efc1a3c049f0a1bcd9b65e0faeb751ce5ec6 (patch)
tree5c750ab134bb1037eeaf5baa8d9eee6196566226 /drivers/mtd
parent0c6c7fa1313fcb69cae35e34168d2e83b8da854a (diff)
downloadlinux-fe96efc1a3c049f0a1bcd9b65e0faeb751ce5ec6.tar.bz2
UBI: nicify image sequence number handling
Move the image seq. number handling from I/O level to the scanning lever, where it really belongs to. Move the @image_seq_set variable to the @struct ubi_scan_info structure, which exists only during scanning. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/ubi/io.c14
-rw-r--r--drivers/mtd/ubi/scan.c16
-rw-r--r--drivers/mtd/ubi/scan.h2
-rw-r--r--drivers/mtd/ubi/ubi.h2
4 files changed, 18 insertions, 16 deletions
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index b58714011091..1ea14218de02 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -563,16 +563,15 @@ int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum)
* This function returns zero if the erase counter header is OK, and %1 if
* not.
*/
-static int validate_ec_hdr(struct ubi_device *ubi,
+static int validate_ec_hdr(const struct ubi_device *ubi,
const struct ubi_ec_hdr *ec_hdr)
{
long long ec;
- int vid_hdr_offset, leb_start, image_seq;
+ int vid_hdr_offset, leb_start;
ec = be64_to_cpu(ec_hdr->ec);
vid_hdr_offset = be32_to_cpu(ec_hdr->vid_hdr_offset);
leb_start = be32_to_cpu(ec_hdr->data_offset);
- image_seq = be32_to_cpu(ec_hdr->image_seq);
if (ec_hdr->version != UBI_VERSION) {
ubi_err("node with incompatible UBI version found: "
@@ -598,15 +597,6 @@ static int validate_ec_hdr(struct ubi_device *ubi,
goto bad;
}
- if (!ubi->image_seq_set) {
- ubi->image_seq = image_seq;
- ubi->image_seq_set = 1;
- } else if (ubi->image_seq != image_seq) {
- ubi_err("bad image sequence number %d, expected %d",
- image_seq, ubi->image_seq);
- goto bad;
- }
-
return 0;
bad:
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 72570ed7d33f..f60895ee0aeb 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -757,6 +757,8 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
si->is_empty = 0;
if (!ec_corr) {
+ int image_seq;
+
/* Make sure UBI version is OK */
if (ech->version != UBI_VERSION) {
ubi_err("this UBI version is %d, image version is %d",
@@ -778,6 +780,18 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
ubi_dbg_dump_ec_hdr(ech);
return -EINVAL;
}
+
+ image_seq = be32_to_cpu(ech->ec);
+ if (!si->image_seq_set) {
+ ubi->image_seq = image_seq;
+ si->image_seq_set = 1;
+ } else if (ubi->image_seq != image_seq) {
+ ubi_err("bad image sequence number %d in PEB %d, "
+ "expected %d", image_seq, pnum, ubi->image_seq);
+ ubi_dbg_dump_ec_hdr(ech);
+ return -EINVAL;
+ }
+
}
/* OK, we've done with the EC header, let's look at the VID header */
@@ -910,8 +924,6 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
if (si->is_empty)
ubi_msg("empty MTD device detected");
- ubi->image_seq_set = 1;
-
/*
* In case of unknown erase counter we use the mean erase counter
* value.
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h
index 61df208e2f20..1017cf12def5 100644
--- a/drivers/mtd/ubi/scan.h
+++ b/drivers/mtd/ubi/scan.h
@@ -102,6 +102,7 @@ struct ubi_scan_volume {
* @mean_ec: mean erase counter value
* @ec_sum: a temporary variable used when calculating @mean_ec
* @ec_count: a temporary variable used when calculating @mean_ec
+ * @image_seq_set: indicates @ubi->image_seq is known
*
* This data structure contains the result of scanning and may be used by other
* UBI sub-systems to build final UBI data structures, further error-recovery
@@ -124,6 +125,7 @@ struct ubi_scan_info {
int mean_ec;
uint64_t ec_sum;
int ec_count;
+ int image_seq_set;
};
struct ubi_device;
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index bb372c4222b7..64604e8809ec 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -302,7 +302,6 @@ struct ubi_wl_entry;
* @vol->ref_count, @vol->mapping and @vol->eba_tbl.
* @ref_count: count of references on the UBI device
* @image_seq: image sequence number recorded on EC headers
- * @image_seq_set: indicates @image_seq is known
*
* @rsvd_pebs: count of reserved physical eraseblocks
* @avail_pebs: count of available physical eraseblocks
@@ -393,7 +392,6 @@ struct ubi_device {
spinlock_t volumes_lock;
int ref_count;
int image_seq;
- int image_seq_set;
int rsvd_pebs;
int avail_pebs;