aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
authorRichard Weinberger <richard@nod.at>2012-05-14 11:55:51 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2012-05-20 13:25:59 -0400
commitb36a261e8c0ab323d04db9cdd1f6bb4c273c4b32 (patch)
tree00c90c5fa556f335338f4f61c808d4dfe502bb74 /drivers/mtd/ubi
parent0964f6a27b3574d9210c59ec883cbb3fff78a78d (diff)
UBI: Kill data type hint
We do not need this feature and to our shame it even was not working and there was a bug found very recently. -- Artem Bityutskiy Without the data type hint UBI2 (fastmap) will be easier to implement. Signed-off-by: Richard Weinberger <richard@nod.at> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/cdev.c8
-rw-r--r--drivers/mtd/ubi/eba.c20
-rw-r--r--drivers/mtd/ubi/gluebi.c2
-rw-r--r--drivers/mtd/ubi/kapi.c30
-rw-r--r--drivers/mtd/ubi/ubi.h12
-rw-r--r--drivers/mtd/ubi/upd.c12
-rw-r--r--drivers/mtd/ubi/vtbl.c4
-rw-r--r--drivers/mtd/ubi/wl.c50
8 files changed, 36 insertions, 102 deletions
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index ad76592fb2f4..f4061126926b 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -334,8 +334,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
334 break; 334 break;
335 } 335 }
336 336
337 err = ubi_eba_write_leb(ubi, vol, lnum, tbuf, off, len, 337 err = ubi_eba_write_leb(ubi, vol, lnum, tbuf, off, len);
338 UBI_UNKNOWN);
339 if (err) 338 if (err)
340 break; 339 break;
341 340
@@ -477,9 +476,6 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
477 if (req.lnum < 0 || req.lnum >= vol->reserved_pebs || 476 if (req.lnum < 0 || req.lnum >= vol->reserved_pebs ||
478 req.bytes < 0 || req.lnum >= vol->usable_leb_size) 477 req.bytes < 0 || req.lnum >= vol->usable_leb_size)
479 break; 478 break;
480 if (req.dtype != UBI_LONGTERM && req.dtype != UBI_SHORTTERM &&
481 req.dtype != UBI_UNKNOWN)
482 break;
483 479
484 err = get_exclusive(desc); 480 err = get_exclusive(desc);
485 if (err < 0) 481 if (err < 0)
@@ -532,7 +528,7 @@ static long vol_cdev_ioctl(struct file *file, unsigned int cmd,
532 err = -EFAULT; 528 err = -EFAULT;
533 break; 529 break;
534 } 530 }
535 err = ubi_leb_map(desc, req.lnum, req.dtype); 531 err = ubi_leb_map(desc, req.lnum);
536 break; 532 break;
537 } 533 }
538 534
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 2455d620d96b..bd5fdbf7cb41 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -507,7 +507,7 @@ static int recover_peb(struct ubi_device *ubi, int pnum, int vol_id, int lnum,
507 return -ENOMEM; 507 return -ENOMEM;
508 508
509retry: 509retry:
510 new_pnum = ubi_wl_get_peb(ubi, UBI_UNKNOWN); 510 new_pnum = ubi_wl_get_peb(ubi);
511 if (new_pnum < 0) { 511 if (new_pnum < 0) {
512 ubi_free_vid_hdr(ubi, vid_hdr); 512 ubi_free_vid_hdr(ubi, vid_hdr);
513 return new_pnum; 513 return new_pnum;
@@ -585,7 +585,6 @@ write_error:
585 * @buf: the data to write 585 * @buf: the data to write
586 * @offset: offset within the logical eraseblock where to write 586 * @offset: offset within the logical eraseblock where to write
587 * @len: how many bytes to write 587 * @len: how many bytes to write
588 * @dtype: data type
589 * 588 *
590 * This function writes data to logical eraseblock @lnum of a dynamic volume 589 * This function writes data to logical eraseblock @lnum of a dynamic volume
591 * @vol. Returns zero in case of success and a negative error code in case 590 * @vol. Returns zero in case of success and a negative error code in case
@@ -593,7 +592,7 @@ write_error:
593 * written to the flash media, but may be some garbage. 592 * written to the flash media, but may be some garbage.
594 */ 593 */
595int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, 594int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
596 const void *buf, int offset, int len, int dtype) 595 const void *buf, int offset, int len)
597{ 596{
598 int err, pnum, tries = 0, vol_id = vol->vol_id; 597 int err, pnum, tries = 0, vol_id = vol->vol_id;
599 struct ubi_vid_hdr *vid_hdr; 598 struct ubi_vid_hdr *vid_hdr;
@@ -641,7 +640,7 @@ int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
641 vid_hdr->data_pad = cpu_to_be32(vol->data_pad); 640 vid_hdr->data_pad = cpu_to_be32(vol->data_pad);
642 641
643retry: 642retry:
644 pnum = ubi_wl_get_peb(ubi, dtype); 643 pnum = ubi_wl_get_peb(ubi);
645 if (pnum < 0) { 644 if (pnum < 0) {
646 ubi_free_vid_hdr(ubi, vid_hdr); 645 ubi_free_vid_hdr(ubi, vid_hdr);
647 leb_write_unlock(ubi, vol_id, lnum); 646 leb_write_unlock(ubi, vol_id, lnum);
@@ -707,7 +706,6 @@ write_error:
707 * @lnum: logical eraseblock number 706 * @lnum: logical eraseblock number
708 * @buf: data to write 707 * @buf: data to write
709 * @len: how many bytes to write 708 * @len: how many bytes to write
710 * @dtype: data type
711 * @used_ebs: how many logical eraseblocks will this volume contain 709 * @used_ebs: how many logical eraseblocks will this volume contain
712 * 710 *
713 * This function writes data to logical eraseblock @lnum of static volume 711 * This function writes data to logical eraseblock @lnum of static volume
@@ -724,8 +722,7 @@ write_error:
724 * code in case of failure. 722 * code in case of failure.
725 */ 723 */
726int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol, 724int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
727 int lnum, const void *buf, int len, int dtype, 725 int lnum, const void *buf, int len, int used_ebs)
728 int used_ebs)
729{ 726{
730 int err, pnum, tries = 0, data_size = len, vol_id = vol->vol_id; 727 int err, pnum, tries = 0, data_size = len, vol_id = vol->vol_id;
731 struct ubi_vid_hdr *vid_hdr; 728 struct ubi_vid_hdr *vid_hdr;
@@ -763,7 +760,7 @@ int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
763 vid_hdr->data_crc = cpu_to_be32(crc); 760 vid_hdr->data_crc = cpu_to_be32(crc);
764 761
765retry: 762retry:
766 pnum = ubi_wl_get_peb(ubi, dtype); 763 pnum = ubi_wl_get_peb(ubi);
767 if (pnum < 0) { 764 if (pnum < 0) {
768 ubi_free_vid_hdr(ubi, vid_hdr); 765 ubi_free_vid_hdr(ubi, vid_hdr);
769 leb_write_unlock(ubi, vol_id, lnum); 766 leb_write_unlock(ubi, vol_id, lnum);
@@ -827,7 +824,6 @@ write_error:
827 * @lnum: logical eraseblock number 824 * @lnum: logical eraseblock number
828 * @buf: data to write 825 * @buf: data to write
829 * @len: how many bytes to write 826 * @len: how many bytes to write
830 * @dtype: data type
831 * 827 *
832 * This function changes the contents of a logical eraseblock atomically. @buf 828 * This function changes the contents of a logical eraseblock atomically. @buf
833 * has to contain new logical eraseblock data, and @len - the length of the 829 * has to contain new logical eraseblock data, and @len - the length of the
@@ -839,7 +835,7 @@ write_error:
839 * LEB change may be done at a time. This is ensured by @ubi->alc_mutex. 835 * LEB change may be done at a time. This is ensured by @ubi->alc_mutex.
840 */ 836 */
841int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, 837int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
842 int lnum, const void *buf, int len, int dtype) 838 int lnum, const void *buf, int len)
843{ 839{
844 int err, pnum, tries = 0, vol_id = vol->vol_id; 840 int err, pnum, tries = 0, vol_id = vol->vol_id;
845 struct ubi_vid_hdr *vid_hdr; 841 struct ubi_vid_hdr *vid_hdr;
@@ -856,7 +852,7 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
856 err = ubi_eba_unmap_leb(ubi, vol, lnum); 852 err = ubi_eba_unmap_leb(ubi, vol, lnum);
857 if (err) 853 if (err)
858 return err; 854 return err;
859 return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype); 855 return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0);
860 } 856 }
861 857
862 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); 858 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
@@ -881,7 +877,7 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
881 vid_hdr->data_crc = cpu_to_be32(crc); 877 vid_hdr->data_crc = cpu_to_be32(crc);
882 878
883retry: 879retry:
884 pnum = ubi_wl_get_peb(ubi, dtype); 880 pnum = ubi_wl_get_peb(ubi);
885 if (pnum < 0) { 881 if (pnum < 0) {
886 err = pnum; 882 err = pnum;
887 goto out_leb_unlock; 883 goto out_leb_unlock;
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index 90b98822d9a4..4e44bee4c564 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -227,7 +227,7 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len,
227 if (to_write > total_written) 227 if (to_write > total_written)
228 to_write = total_written; 228 to_write = total_written;
229 229
230 err = ubi_write(gluebi->desc, lnum, buf, offs, to_write); 230 err = ubi_leb_write(gluebi->desc, lnum, buf, offs, to_write);
231 if (err) 231 if (err)
232 break; 232 break;
233 233
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 9fdb35367fe0..33ede23769db 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -426,11 +426,9 @@ EXPORT_SYMBOL_GPL(ubi_leb_read);
426 * @buf: data to write 426 * @buf: data to write
427 * @offset: offset within the logical eraseblock where to write 427 * @offset: offset within the logical eraseblock where to write
428 * @len: how many bytes to write 428 * @len: how many bytes to write
429 * @dtype: expected data type
430 * 429 *
431 * This function writes @len bytes of data from @buf to offset @offset of 430 * This function writes @len bytes of data from @buf to offset @offset of
432 * logical eraseblock @lnum. The @dtype argument describes expected lifetime of 431 * logical eraseblock @lnum.
433 * the data.
434 * 432 *
435 * This function takes care of physical eraseblock write failures. If write to 433 * This function takes care of physical eraseblock write failures. If write to
436 * the physical eraseblock write operation fails, the logical eraseblock is 434 * the physical eraseblock write operation fails, the logical eraseblock is
@@ -447,7 +445,7 @@ EXPORT_SYMBOL_GPL(ubi_leb_read);
447 * returns immediately with %-EBADF code. 445 * returns immediately with %-EBADF code.
448 */ 446 */
449int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, 447int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
450 int offset, int len, int dtype) 448 int offset, int len)
451{ 449{
452 struct ubi_volume *vol = desc->vol; 450 struct ubi_volume *vol = desc->vol;
453 struct ubi_device *ubi = vol->ubi; 451 struct ubi_device *ubi = vol->ubi;
@@ -466,17 +464,13 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
466 offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1)) 464 offset & (ubi->min_io_size - 1) || len & (ubi->min_io_size - 1))
467 return -EINVAL; 465 return -EINVAL;
468 466
469 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM &&
470 dtype != UBI_UNKNOWN)
471 return -EINVAL;
472
473 if (vol->upd_marker) 467 if (vol->upd_marker)
474 return -EBADF; 468 return -EBADF;
475 469
476 if (len == 0) 470 if (len == 0)
477 return 0; 471 return 0;
478 472
479 return ubi_eba_write_leb(ubi, vol, lnum, buf, offset, len, dtype); 473 return ubi_eba_write_leb(ubi, vol, lnum, buf, offset, len);
480} 474}
481EXPORT_SYMBOL_GPL(ubi_leb_write); 475EXPORT_SYMBOL_GPL(ubi_leb_write);
482 476
@@ -486,7 +480,6 @@ EXPORT_SYMBOL_GPL(ubi_leb_write);
486 * @lnum: logical eraseblock number to change 480 * @lnum: logical eraseblock number to change
487 * @buf: data to write 481 * @buf: data to write
488 * @len: how many bytes to write 482 * @len: how many bytes to write
489 * @dtype: expected data type
490 * 483 *
491 * This function changes the contents of a logical eraseblock atomically. @buf 484 * This function changes the contents of a logical eraseblock atomically. @buf
492 * has to contain new logical eraseblock data, and @len - the length of the 485 * has to contain new logical eraseblock data, and @len - the length of the
@@ -497,7 +490,7 @@ EXPORT_SYMBOL_GPL(ubi_leb_write);
497 * code in case of failure. 490 * code in case of failure.
498 */ 491 */
499int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, 492int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
500 int len, int dtype) 493 int len)
501{ 494{
502 struct ubi_volume *vol = desc->vol; 495 struct ubi_volume *vol = desc->vol;
503 struct ubi_device *ubi = vol->ubi; 496 struct ubi_device *ubi = vol->ubi;
@@ -515,17 +508,13 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
515 len > vol->usable_leb_size || len & (ubi->min_io_size - 1)) 508 len > vol->usable_leb_size || len & (ubi->min_io_size - 1))
516 return -EINVAL; 509 return -EINVAL;
517 510
518 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM &&
519 dtype != UBI_UNKNOWN)
520 return -EINVAL;
521
522 if (vol->upd_marker) 511 if (vol->upd_marker)
523 return -EBADF; 512 return -EBADF;
524 513
525 if (len == 0) 514 if (len == 0)
526 return 0; 515 return 0;
527 516
528 return ubi_eba_atomic_leb_change(ubi, vol, lnum, buf, len, dtype); 517 return ubi_eba_atomic_leb_change(ubi, vol, lnum, buf, len);
529} 518}
530EXPORT_SYMBOL_GPL(ubi_leb_change); 519EXPORT_SYMBOL_GPL(ubi_leb_change);
531 520
@@ -626,7 +615,6 @@ EXPORT_SYMBOL_GPL(ubi_leb_unmap);
626 * ubi_leb_map - map logical eraseblock to a physical eraseblock. 615 * ubi_leb_map - map logical eraseblock to a physical eraseblock.
627 * @desc: volume descriptor 616 * @desc: volume descriptor
628 * @lnum: logical eraseblock number 617 * @lnum: logical eraseblock number
629 * @dtype: expected data type
630 * 618 *
631 * This function maps an un-mapped logical eraseblock @lnum to a physical 619 * This function maps an un-mapped logical eraseblock @lnum to a physical
632 * eraseblock. This means, that after a successful invocation of this 620 * eraseblock. This means, that after a successful invocation of this
@@ -639,7 +627,7 @@ EXPORT_SYMBOL_GPL(ubi_leb_unmap);
639 * eraseblock is already mapped, and other negative error codes in case of 627 * eraseblock is already mapped, and other negative error codes in case of
640 * other failures. 628 * other failures.
641 */ 629 */
642int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype) 630int ubi_leb_map(struct ubi_volume_desc *desc, int lnum)
643{ 631{
644 struct ubi_volume *vol = desc->vol; 632 struct ubi_volume *vol = desc->vol;
645 struct ubi_device *ubi = vol->ubi; 633 struct ubi_device *ubi = vol->ubi;
@@ -652,17 +640,13 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype)
652 if (lnum < 0 || lnum >= vol->reserved_pebs) 640 if (lnum < 0 || lnum >= vol->reserved_pebs)
653 return -EINVAL; 641 return -EINVAL;
654 642
655 if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM &&
656 dtype != UBI_UNKNOWN)
657 return -EINVAL;
658
659 if (vol->upd_marker) 643 if (vol->upd_marker)
660 return -EBADF; 644 return -EBADF;
661 645
662 if (vol->eba_tbl[lnum] >= 0) 646 if (vol->eba_tbl[lnum] >= 0)
663 return -EBADMSG; 647 return -EBADMSG;
664 648
665 return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype); 649 return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0);
666} 650}
667EXPORT_SYMBOL_GPL(ubi_leb_map); 651EXPORT_SYMBOL_GPL(ubi_leb_map);
668 652
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 4f5c9f136519..75b9f1c61b78 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -222,8 +222,6 @@ struct ubi_volume_desc;
222 * @upd_ebs: how many eraseblocks are expected to be updated 222 * @upd_ebs: how many eraseblocks are expected to be updated
223 * @ch_lnum: LEB number which is being changing by the atomic LEB change 223 * @ch_lnum: LEB number which is being changing by the atomic LEB change
224 * operation 224 * operation
225 * @ch_dtype: data persistency type which is being changing by the atomic LEB
226 * change operation
227 * @upd_bytes: how many bytes are expected to be received for volume update or 225 * @upd_bytes: how many bytes are expected to be received for volume update or
228 * atomic LEB change 226 * atomic LEB change
229 * @upd_received: how many bytes were already received for volume update or 227 * @upd_received: how many bytes were already received for volume update or
@@ -270,7 +268,6 @@ struct ubi_volume {
270 268
271 int upd_ebs; 269 int upd_ebs;
272 int ch_lnum; 270 int ch_lnum;
273 int ch_dtype;
274 long long upd_bytes; 271 long long upd_bytes;
275 long long upd_received; 272 long long upd_received;
276 void *upd_buf; 273 void *upd_buf;
@@ -525,18 +522,17 @@ int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
525int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, 522int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
526 void *buf, int offset, int len, int check); 523 void *buf, int offset, int len, int check);
527int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, 524int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
528 const void *buf, int offset, int len, int dtype); 525 const void *buf, int offset, int len);
529int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol, 526int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
530 int lnum, const void *buf, int len, int dtype, 527 int lnum, const void *buf, int len, int used_ebs);
531 int used_ebs);
532int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, 528int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
533 int lnum, const void *buf, int len, int dtype); 529 int lnum, const void *buf, int len);
534int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, 530int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
535 struct ubi_vid_hdr *vid_hdr); 531 struct ubi_vid_hdr *vid_hdr);
536int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si); 532int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si);
537 533
538/* wl.c */ 534/* wl.c */
539int ubi_wl_get_peb(struct ubi_device *ubi, int dtype); 535int ubi_wl_get_peb(struct ubi_device *ubi);
540int ubi_wl_put_peb(struct ubi_device *ubi, int pnum, int torture); 536int ubi_wl_put_peb(struct ubi_device *ubi, int pnum, int torture);
541int ubi_wl_flush(struct ubi_device *ubi); 537int ubi_wl_flush(struct ubi_device *ubi);
542int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum); 538int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum);
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index 425bf5a3edd4..11a28f9ce0db 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -186,14 +186,12 @@ int ubi_start_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
186 dbg_gen("start changing LEB %d:%d, %u bytes", 186 dbg_gen("start changing LEB %d:%d, %u bytes",
187 vol->vol_id, req->lnum, req->bytes); 187 vol->vol_id, req->lnum, req->bytes);
188 if (req->bytes == 0) 188 if (req->bytes == 0)
189 return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0, 189 return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0);
190 req->dtype);
191 190
192 vol->upd_bytes = req->bytes; 191 vol->upd_bytes = req->bytes;
193 vol->upd_received = 0; 192 vol->upd_received = 0;
194 vol->changing_leb = 1; 193 vol->changing_leb = 1;
195 vol->ch_lnum = req->lnum; 194 vol->ch_lnum = req->lnum;
196 vol->ch_dtype = req->dtype;
197 195
198 vol->upd_buf = vmalloc(req->bytes); 196 vol->upd_buf = vmalloc(req->bytes);
199 if (!vol->upd_buf) 197 if (!vol->upd_buf)
@@ -246,8 +244,7 @@ static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
246 return 0; 244 return 0;
247 } 245 }
248 246
249 err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len, 247 err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len);
250 UBI_UNKNOWN);
251 } else { 248 } else {
252 /* 249 /*
253 * When writing static volume, and this is the last logical 250 * When writing static volume, and this is the last logical
@@ -259,8 +256,7 @@ static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
259 * contain zeros, not random trash. 256 * contain zeros, not random trash.
260 */ 257 */
261 memset(buf + len, 0, vol->usable_leb_size - len); 258 memset(buf + len, 0, vol->usable_leb_size - len);
262 err = ubi_eba_write_leb_st(ubi, vol, lnum, buf, len, 259 err = ubi_eba_write_leb_st(ubi, vol, lnum, buf, len, used_ebs);
263 UBI_UNKNOWN, used_ebs);
264 } 260 }
265 261
266 return err; 262 return err;
@@ -421,7 +417,7 @@ int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol,
421 len - vol->upd_bytes); 417 len - vol->upd_bytes);
422 len = ubi_calc_data_len(ubi, vol->upd_buf, len); 418 len = ubi_calc_data_len(ubi, vol->upd_buf, len);
423 err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum, 419 err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum,
424 vol->upd_buf, len, UBI_UNKNOWN); 420 vol->upd_buf, len);
425 if (err) 421 if (err)
426 return err; 422 return err;
427 } 423 }
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 17cec0c01544..a6f4b13d8417 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -106,7 +106,7 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
106 return err; 106 return err;
107 107
108 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, 108 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
109 ubi->vtbl_size, UBI_LONGTERM); 109 ubi->vtbl_size);
110 if (err) 110 if (err)
111 return err; 111 return err;
112 } 112 }
@@ -158,7 +158,7 @@ int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
158 return err; 158 return err;
159 159
160 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, 160 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
161 ubi->vtbl_size, UBI_LONGTERM); 161 ubi->vtbl_size);
162 if (err) 162 if (err)
163 return err; 163 return err;
164 } 164 }
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index b0a6d53ef047..f0bc10743bc0 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -383,19 +383,15 @@ static struct ubi_wl_entry *find_wl_entry(struct rb_root *root, int diff)
383/** 383/**
384 * ubi_wl_get_peb - get a physical eraseblock. 384 * ubi_wl_get_peb - get a physical eraseblock.
385 * @ubi: UBI device description object 385 * @ubi: UBI device description object
386 * @dtype: type of data which will be stored in this physical eraseblock
387 * 386 *
388 * This function returns a physical eraseblock in case of success and a 387 * This function returns a physical eraseblock in case of success and a
389 * negative error code in case of failure. Might sleep. 388 * negative error code in case of failure. Might sleep.
390 */ 389 */
391int ubi_wl_get_peb(struct ubi_device *ubi, int dtype) 390int ubi_wl_get_peb(struct ubi_device *ubi)
392{ 391{
393 int err; 392 int err;
394 struct ubi_wl_entry *e, *first, *last; 393 struct ubi_wl_entry *e, *first, *last;
395 394
396 ubi_assert(dtype == UBI_LONGTERM || dtype == UBI_SHORTTERM ||
397 dtype == UBI_UNKNOWN);
398
399retry: 395retry:
400 spin_lock(&ubi->wl_lock); 396 spin_lock(&ubi->wl_lock);
401 if (!ubi->free.rb_node) { 397 if (!ubi->free.rb_node) {
@@ -413,43 +409,13 @@ retry:
413 goto retry; 409 goto retry;
414 } 410 }
415 411
416 switch (dtype) { 412 first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, u.rb);
417 case UBI_LONGTERM: 413 last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, u.rb);
418 /* 414
419 * For long term data we pick a physical eraseblock with high 415 if (last->ec - first->ec < WL_FREE_MAX_DIFF)
420 * erase counter. But the highest erase counter we can pick is 416 e = rb_entry(ubi->free.rb_node, struct ubi_wl_entry, u.rb);
421 * bounded by the the lowest erase counter plus 417 else
422 * %WL_FREE_MAX_DIFF. 418 e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF/2);
423 */
424 e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF);
425 break;
426 case UBI_UNKNOWN:
427 /*
428 * For unknown data we pick a physical eraseblock with medium
429 * erase counter. But we by no means can pick a physical
430 * eraseblock with erase counter greater or equivalent than the
431 * lowest erase counter plus %WL_FREE_MAX_DIFF/2.
432 */
433 first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry,
434 u.rb);
435 last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, u.rb);
436
437 if (last->ec - first->ec < WL_FREE_MAX_DIFF)
438 e = rb_entry(ubi->free.rb_node,
439 struct ubi_wl_entry, u.rb);
440 else
441 e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF/2);
442 break;
443 case UBI_SHORTTERM:
444 /*
445 * For short term data we pick a physical eraseblock with the
446 * lowest erase counter as we expect it will be erased soon.
447 */
448 e = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, u.rb);
449 break;
450 default:
451 BUG();
452 }
453 419
454 paranoid_check_in_wl_tree(ubi, e, &ubi->free); 420 paranoid_check_in_wl_tree(ubi, e, &ubi->free);
455 421