diff options
author | David Woodhouse <dwmw2@infradead.org> | 2007-10-14 09:29:00 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@infradead.org> | 2007-10-14 09:29:00 -0400 |
commit | e3d18658d4f28e4783e1bb1c41e9134c9e5db0a9 (patch) | |
tree | d4fe529460e98522775bc0ecca557dcc76866999 /drivers/mtd/ubi/scan.c | |
parent | a2e1b833d9e0231d67e722b7e2f4d79daf919baf (diff) | |
parent | cc5f4f28755b3b152297fd7bc3e03781dd8008e2 (diff) |
Merge branch 'master' of git://git.infradead.org/~dedekind/ubi-2.6
Diffstat (limited to 'drivers/mtd/ubi/scan.c')
-rw-r--r-- | drivers/mtd/ubi/scan.c | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 29c41eeb09fe..c7b0afc9d280 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
@@ -45,8 +45,7 @@ | |||
45 | #include "ubi.h" | 45 | #include "ubi.h" |
46 | 46 | ||
47 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID | 47 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID |
48 | static int paranoid_check_si(const struct ubi_device *ubi, | 48 | static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si); |
49 | struct ubi_scan_info *si); | ||
50 | #else | 49 | #else |
51 | #define paranoid_check_si(ubi, si) 0 | 50 | #define paranoid_check_si(ubi, si) 0 |
52 | #endif | 51 | #endif |
@@ -259,14 +258,13 @@ static struct ubi_scan_volume *add_volume(struct ubi_scan_info *si, int vol_id, | |||
259 | * o bit 2 is cleared: the older LEB is not corrupted; | 258 | * o bit 2 is cleared: the older LEB is not corrupted; |
260 | * o bit 2 is set: the older LEB is corrupted. | 259 | * o bit 2 is set: the older LEB is corrupted. |
261 | */ | 260 | */ |
262 | static int compare_lebs(const struct ubi_device *ubi, | 261 | static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb, |
263 | const struct ubi_scan_leb *seb, int pnum, | 262 | int pnum, const struct ubi_vid_hdr *vid_hdr) |
264 | const struct ubi_vid_hdr *vid_hdr) | ||
265 | { | 263 | { |
266 | void *buf; | 264 | void *buf; |
267 | int len, err, second_is_newer, bitflips = 0, corrupted = 0; | 265 | int len, err, second_is_newer, bitflips = 0, corrupted = 0; |
268 | uint32_t data_crc, crc; | 266 | uint32_t data_crc, crc; |
269 | struct ubi_vid_hdr *vidh = NULL; | 267 | struct ubi_vid_hdr *vh = NULL; |
270 | unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); | 268 | unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum); |
271 | 269 | ||
272 | if (seb->sqnum == 0 && sqnum2 == 0) { | 270 | if (seb->sqnum == 0 && sqnum2 == 0) { |
@@ -323,11 +321,11 @@ static int compare_lebs(const struct ubi_device *ubi, | |||
323 | } else { | 321 | } else { |
324 | pnum = seb->pnum; | 322 | pnum = seb->pnum; |
325 | 323 | ||
326 | vidh = ubi_zalloc_vid_hdr(ubi); | 324 | vh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); |
327 | if (!vidh) | 325 | if (!vh) |
328 | return -ENOMEM; | 326 | return -ENOMEM; |
329 | 327 | ||
330 | err = ubi_io_read_vid_hdr(ubi, pnum, vidh, 0); | 328 | err = ubi_io_read_vid_hdr(ubi, pnum, vh, 0); |
331 | if (err) { | 329 | if (err) { |
332 | if (err == UBI_IO_BITFLIPS) | 330 | if (err == UBI_IO_BITFLIPS) |
333 | bitflips = 1; | 331 | bitflips = 1; |
@@ -341,7 +339,7 @@ static int compare_lebs(const struct ubi_device *ubi, | |||
341 | } | 339 | } |
342 | } | 340 | } |
343 | 341 | ||
344 | if (!vidh->copy_flag) { | 342 | if (!vh->copy_flag) { |
345 | /* It is not a copy, so it is newer */ | 343 | /* It is not a copy, so it is newer */ |
346 | dbg_bld("first PEB %d is newer, copy_flag is unset", | 344 | dbg_bld("first PEB %d is newer, copy_flag is unset", |
347 | pnum); | 345 | pnum); |
@@ -349,7 +347,7 @@ static int compare_lebs(const struct ubi_device *ubi, | |||
349 | goto out_free_vidh; | 347 | goto out_free_vidh; |
350 | } | 348 | } |
351 | 349 | ||
352 | vid_hdr = vidh; | 350 | vid_hdr = vh; |
353 | } | 351 | } |
354 | 352 | ||
355 | /* Read the data of the copy and check the CRC */ | 353 | /* Read the data of the copy and check the CRC */ |
@@ -379,7 +377,7 @@ static int compare_lebs(const struct ubi_device *ubi, | |||
379 | } | 377 | } |
380 | 378 | ||
381 | vfree(buf); | 379 | vfree(buf); |
382 | ubi_free_vid_hdr(ubi, vidh); | 380 | ubi_free_vid_hdr(ubi, vh); |
383 | 381 | ||
384 | if (second_is_newer) | 382 | if (second_is_newer) |
385 | dbg_bld("second PEB %d is newer, copy_flag is set", pnum); | 383 | dbg_bld("second PEB %d is newer, copy_flag is set", pnum); |
@@ -391,7 +389,7 @@ static int compare_lebs(const struct ubi_device *ubi, | |||
391 | out_free_buf: | 389 | out_free_buf: |
392 | vfree(buf); | 390 | vfree(buf); |
393 | out_free_vidh: | 391 | out_free_vidh: |
394 | ubi_free_vid_hdr(ubi, vidh); | 392 | ubi_free_vid_hdr(ubi, vh); |
395 | ubi_assert(err < 0); | 393 | ubi_assert(err < 0); |
396 | return err; | 394 | return err; |
397 | } | 395 | } |
@@ -413,7 +411,7 @@ out_free_vidh: | |||
413 | * to be picked, while the older one has to be dropped. This function returns | 411 | * to be picked, while the older one has to be dropped. This function returns |
414 | * zero in case of success and a negative error code in case of failure. | 412 | * zero in case of success and a negative error code in case of failure. |
415 | */ | 413 | */ |
416 | int ubi_scan_add_used(const struct ubi_device *ubi, struct ubi_scan_info *si, | 414 | int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, |
417 | int pnum, int ec, const struct ubi_vid_hdr *vid_hdr, | 415 | int pnum, int ec, const struct ubi_vid_hdr *vid_hdr, |
418 | int bitflips) | 416 | int bitflips) |
419 | { | 417 | { |
@@ -667,16 +665,12 @@ void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv) | |||
667 | * function returns zero in case of success and a negative error code in case | 665 | * function returns zero in case of success and a negative error code in case |
668 | * of failure. | 666 | * of failure. |
669 | */ | 667 | */ |
670 | int ubi_scan_erase_peb(const struct ubi_device *ubi, | 668 | int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si, |
671 | const struct ubi_scan_info *si, int pnum, int ec) | 669 | int pnum, int ec) |
672 | { | 670 | { |
673 | int err; | 671 | int err; |
674 | struct ubi_ec_hdr *ec_hdr; | 672 | struct ubi_ec_hdr *ec_hdr; |
675 | 673 | ||
676 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); | ||
677 | if (!ec_hdr) | ||
678 | return -ENOMEM; | ||
679 | |||
680 | if ((long long)ec >= UBI_MAX_ERASECOUNTER) { | 674 | if ((long long)ec >= UBI_MAX_ERASECOUNTER) { |
681 | /* | 675 | /* |
682 | * Erase counter overflow. Upgrade UBI and use 64-bit | 676 | * Erase counter overflow. Upgrade UBI and use 64-bit |
@@ -686,6 +680,10 @@ int ubi_scan_erase_peb(const struct ubi_device *ubi, | |||
686 | return -EINVAL; | 680 | return -EINVAL; |
687 | } | 681 | } |
688 | 682 | ||
683 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL); | ||
684 | if (!ec_hdr) | ||
685 | return -ENOMEM; | ||
686 | |||
689 | ec_hdr->ec = cpu_to_be64(ec); | 687 | ec_hdr->ec = cpu_to_be64(ec); |
690 | 688 | ||
691 | err = ubi_io_sync_erase(ubi, pnum, 0); | 689 | err = ubi_io_sync_erase(ubi, pnum, 0); |
@@ -712,7 +710,7 @@ out_free: | |||
712 | * This function returns scanning physical eraseblock information in case of | 710 | * This function returns scanning physical eraseblock information in case of |
713 | * success and an error code in case of failure. | 711 | * success and an error code in case of failure. |
714 | */ | 712 | */ |
715 | struct ubi_scan_leb *ubi_scan_get_free_peb(const struct ubi_device *ubi, | 713 | struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi, |
716 | struct ubi_scan_info *si) | 714 | struct ubi_scan_info *si) |
717 | { | 715 | { |
718 | int err = 0, i; | 716 | int err = 0, i; |
@@ -948,7 +946,7 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) | |||
948 | if (!ech) | 946 | if (!ech) |
949 | goto out_si; | 947 | goto out_si; |
950 | 948 | ||
951 | vidh = ubi_zalloc_vid_hdr(ubi); | 949 | vidh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); |
952 | if (!vidh) | 950 | if (!vidh) |
953 | goto out_ech; | 951 | goto out_ech; |
954 | 952 | ||
@@ -1110,8 +1108,7 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si) | |||
1110 | * This function returns zero if the scanning information is all right, %1 if | 1108 | * This function returns zero if the scanning information is all right, %1 if |
1111 | * not and a negative error code if an error occurred. | 1109 | * not and a negative error code if an error occurred. |
1112 | */ | 1110 | */ |
1113 | static int paranoid_check_si(const struct ubi_device *ubi, | 1111 | static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) |
1114 | struct ubi_scan_info *si) | ||
1115 | { | 1112 | { |
1116 | int pnum, err, vols_found = 0; | 1113 | int pnum, err, vols_found = 0; |
1117 | struct rb_node *rb1, *rb2; | 1114 | struct rb_node *rb1, *rb2; |