aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r--drivers/mtd/ubi/build.c4
-rw-r--r--drivers/mtd/ubi/cdev.c6
-rw-r--r--drivers/mtd/ubi/eba.c51
-rw-r--r--drivers/mtd/ubi/gluebi.c9
-rw-r--r--drivers/mtd/ubi/kapi.c12
-rw-r--r--drivers/mtd/ubi/misc.c2
-rw-r--r--drivers/mtd/ubi/ubi.h21
-rw-r--r--drivers/mtd/ubi/upd.c7
-rw-r--r--drivers/mtd/ubi/vmt.c22
-rw-r--r--drivers/mtd/ubi/vtbl.c6
10 files changed, 68 insertions, 72 deletions
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index b85ca186afc6..5d00364d4a4a 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -249,7 +249,7 @@ static void kill_volumes(struct ubi_device *ubi)
249 249
250 for (i = 0; i < ubi->vtbl_slots; i++) 250 for (i = 0; i < ubi->vtbl_slots; i++)
251 if (ubi->volumes[i]) 251 if (ubi->volumes[i])
252 ubi_free_volume(ubi, i); 252 ubi_free_volume(ubi, ubi->volumes[i]);
253} 253}
254 254
255/** 255/**
@@ -300,7 +300,7 @@ static int uif_init(struct ubi_device *ubi)
300 300
301 for (i = 0; i < ubi->vtbl_slots; i++) 301 for (i = 0; i < ubi->vtbl_slots; i++)
302 if (ubi->volumes[i]) { 302 if (ubi->volumes[i]) {
303 err = ubi_add_volume(ubi, i); 303 err = ubi_add_volume(ubi, ubi->volumes[i]);
304 if (err) { 304 if (err) {
305 ubi_err("cannot add volume %d", i); 305 ubi_err("cannot add volume %d", i);
306 goto out_volumes; 306 goto out_volumes;
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index 7697eda2d58c..24344ba3cfed 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -249,7 +249,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
249 if (off + len >= vol->usable_leb_size) 249 if (off + len >= vol->usable_leb_size)
250 len = vol->usable_leb_size - off; 250 len = vol->usable_leb_size - off;
251 251
252 err = ubi_eba_read_leb(ubi, vol_id, lnum, tbuf, off, len, 0); 252 err = ubi_eba_read_leb(ubi, vol, lnum, tbuf, off, len, 0);
253 if (err) 253 if (err)
254 break; 254 break;
255 255
@@ -339,7 +339,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
339 break; 339 break;
340 } 340 }
341 341
342 err = ubi_eba_write_leb(ubi, vol_id, lnum, tbuf, off, len, 342 err = ubi_eba_write_leb(ubi, vol, lnum, tbuf, off, len,
343 UBI_UNKNOWN); 343 UBI_UNKNOWN);
344 if (err) 344 if (err)
345 break; 345 break;
@@ -484,7 +484,7 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file,
484 } 484 }
485 485
486 dbg_msg("erase LEB %d:%d", vol->vol_id, lnum); 486 dbg_msg("erase LEB %d:%d", vol->vol_id, lnum);
487 err = ubi_eba_unmap_leb(ubi, vol->vol_id, lnum); 487 err = ubi_eba_unmap_leb(ubi, vol, lnum);
488 if (err) 488 if (err)
489 break; 489 break;
490 490
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 5fdb31bc5636..b2b0f29bdc53 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -289,17 +289,17 @@ static void leb_write_unlock(struct ubi_device *ubi, int vol_id, int lnum)
289/** 289/**
290 * ubi_eba_unmap_leb - un-map logical eraseblock. 290 * ubi_eba_unmap_leb - un-map logical eraseblock.
291 * @ubi: UBI device description object 291 * @ubi: UBI device description object
292 * @vol_id: volume ID 292 * @vol: volume description object
293 * @lnum: logical eraseblock number 293 * @lnum: logical eraseblock number
294 * 294 *
295 * This function un-maps logical eraseblock @lnum and schedules corresponding 295 * This function un-maps logical eraseblock @lnum and schedules corresponding
296 * physical eraseblock for erasure. Returns zero in case of success and a 296 * physical eraseblock for erasure. Returns zero in case of success and a
297 * negative error code in case of failure. 297 * negative error code in case of failure.
298 */ 298 */
299int ubi_eba_unmap_leb(struct ubi_device *ubi, int vol_id, int lnum) 299int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
300 int lnum)
300{ 301{
301 int idx = vol_id2idx(ubi, vol_id), err, pnum; 302 int err, pnum, vol_id = vol->vol_id;
302 struct ubi_volume *vol = ubi->volumes[idx];
303 303
304 if (ubi->ro_mode) 304 if (ubi->ro_mode)
305 return -EROFS; 305 return -EROFS;
@@ -326,7 +326,7 @@ out_unlock:
326/** 326/**
327 * ubi_eba_read_leb - read data. 327 * ubi_eba_read_leb - read data.
328 * @ubi: UBI device description object 328 * @ubi: UBI device description object
329 * @vol_id: volume ID 329 * @vol: volume description object
330 * @lnum: logical eraseblock number 330 * @lnum: logical eraseblock number
331 * @buf: buffer to store the read data 331 * @buf: buffer to store the read data
332 * @offset: offset from where to read 332 * @offset: offset from where to read
@@ -342,12 +342,11 @@ out_unlock:
342 * returned for any volume type if an ECC error was detected by the MTD device 342 * returned for any volume type if an ECC error was detected by the MTD device
343 * driver. Other negative error cored may be returned in case of other errors. 343 * driver. Other negative error cored may be returned in case of other errors.
344 */ 344 */
345int ubi_eba_read_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf, 345int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
346 int offset, int len, int check) 346 void *buf, int offset, int len, int check)
347{ 347{
348 int err, pnum, scrub = 0, idx = vol_id2idx(ubi, vol_id); 348 int err, pnum, scrub = 0, vol_id = vol->vol_id;
349 struct ubi_vid_hdr *vid_hdr; 349 struct ubi_vid_hdr *vid_hdr;
350 struct ubi_volume *vol = ubi->volumes[idx];
351 uint32_t uninitialized_var(crc); 350 uint32_t uninitialized_var(crc);
352 351
353 err = leb_read_lock(ubi, vol_id, lnum); 352 err = leb_read_lock(ubi, vol_id, lnum);
@@ -555,7 +554,7 @@ write_error:
555/** 554/**
556 * ubi_eba_write_leb - write data to dynamic volume. 555 * ubi_eba_write_leb - write data to dynamic volume.
557 * @ubi: UBI device description object 556 * @ubi: UBI device description object
558 * @vol_id: volume ID 557 * @vol: volume description object
559 * @lnum: logical eraseblock number 558 * @lnum: logical eraseblock number
560 * @buf: the data to write 559 * @buf: the data to write
561 * @offset: offset within the logical eraseblock where to write 560 * @offset: offset within the logical eraseblock where to write
@@ -563,15 +562,14 @@ write_error:
563 * @dtype: data type 562 * @dtype: data type
564 * 563 *
565 * This function writes data to logical eraseblock @lnum of a dynamic volume 564 * This function writes data to logical eraseblock @lnum of a dynamic volume
566 * @vol_id. Returns zero in case of success and a negative error code in case 565 * @vol. Returns zero in case of success and a negative error code in case
567 * of failure. In case of error, it is possible that something was still 566 * of failure. In case of error, it is possible that something was still
568 * written to the flash media, but may be some garbage. 567 * written to the flash media, but may be some garbage.
569 */ 568 */
570int ubi_eba_write_leb(struct ubi_device *ubi, int vol_id, int lnum, 569int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
571 const void *buf, int offset, int len, int dtype) 570 const void *buf, int offset, int len, int dtype)
572{ 571{
573 int idx = vol_id2idx(ubi, vol_id), err, pnum, tries = 0; 572 int err, pnum, tries = 0, vol_id = vol->vol_id;
574 struct ubi_volume *vol = ubi->volumes[idx];
575 struct ubi_vid_hdr *vid_hdr; 573 struct ubi_vid_hdr *vid_hdr;
576 574
577 if (ubi->ro_mode) 575 if (ubi->ro_mode)
@@ -590,7 +588,8 @@ int ubi_eba_write_leb(struct ubi_device *ubi, int vol_id, int lnum,
590 if (err) { 588 if (err) {
591 ubi_warn("failed to write data to PEB %d", pnum); 589 ubi_warn("failed to write data to PEB %d", pnum);
592 if (err == -EIO && ubi->bad_allowed) 590 if (err == -EIO && ubi->bad_allowed)
593 err = recover_peb(ubi, pnum, vol_id, lnum, buf, offset, len); 591 err = recover_peb(ubi, pnum, vol_id, lnum, buf,
592 offset, len);
594 if (err) 593 if (err)
595 ubi_ro_mode(ubi); 594 ubi_ro_mode(ubi);
596 } 595 }
@@ -678,7 +677,7 @@ write_error:
678/** 677/**
679 * ubi_eba_write_leb_st - write data to static volume. 678 * ubi_eba_write_leb_st - write data to static volume.
680 * @ubi: UBI device description object 679 * @ubi: UBI device description object
681 * @vol_id: volume ID 680 * @vol: volume description object
682 * @lnum: logical eraseblock number 681 * @lnum: logical eraseblock number
683 * @buf: data to write 682 * @buf: data to write
684 * @len: how many bytes to write 683 * @len: how many bytes to write
@@ -686,7 +685,7 @@ write_error:
686 * @used_ebs: how many logical eraseblocks will this volume contain 685 * @used_ebs: how many logical eraseblocks will this volume contain
687 * 686 *
688 * This function writes data to logical eraseblock @lnum of static volume 687 * This function writes data to logical eraseblock @lnum of static volume
689 * @vol_id. The @used_ebs argument should contain total number of logical 688 * @vol. The @used_ebs argument should contain total number of logical
690 * eraseblock in this static volume. 689 * eraseblock in this static volume.
691 * 690 *
692 * When writing to the last logical eraseblock, the @len argument doesn't have 691 * When writing to the last logical eraseblock, the @len argument doesn't have
@@ -698,12 +697,11 @@ write_error:
698 * volumes. This function returns zero in case of success and a negative error 697 * volumes. This function returns zero in case of success and a negative error
699 * code in case of failure. 698 * code in case of failure.
700 */ 699 */
701int ubi_eba_write_leb_st(struct ubi_device *ubi, int vol_id, int lnum, 700int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
702 const void *buf, int len, int dtype, int used_ebs) 701 int lnum, const void *buf, int len, int dtype,
702 int used_ebs)
703{ 703{
704 int err, pnum, tries = 0, data_size = len; 704 int err, pnum, tries = 0, data_size = len, vol_id = vol->vol_id;
705 int idx = vol_id2idx(ubi, vol_id);
706 struct ubi_volume *vol = ubi->volumes[idx];
707 struct ubi_vid_hdr *vid_hdr; 705 struct ubi_vid_hdr *vid_hdr;
708 uint32_t crc; 706 uint32_t crc;
709 707
@@ -799,7 +797,7 @@ write_error:
799/* 797/*
800 * ubi_eba_atomic_leb_change - change logical eraseblock atomically. 798 * ubi_eba_atomic_leb_change - change logical eraseblock atomically.
801 * @ubi: UBI device description object 799 * @ubi: UBI device description object
802 * @vol_id: volume ID 800 * @vol: volume escription object
803 * @lnum: logical eraseblock number 801 * @lnum: logical eraseblock number
804 * @buf: data to write 802 * @buf: data to write
805 * @len: how many bytes to write 803 * @len: how many bytes to write
@@ -814,11 +812,10 @@ write_error:
814 * UBI reserves one LEB for the "atomic LEB change" operation, so only one 812 * UBI reserves one LEB for the "atomic LEB change" operation, so only one
815 * LEB change may be done at a time. This is ensured by @ubi->alc_mutex. 813 * LEB change may be done at a time. This is ensured by @ubi->alc_mutex.
816 */ 814 */
817int ubi_eba_atomic_leb_change(struct ubi_device *ubi, int vol_id, int lnum, 815int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
818 const void *buf, int len, int dtype) 816 int lnum, const void *buf, int len, int dtype)
819{ 817{
820 int err, pnum, tries = 0, idx = vol_id2idx(ubi, vol_id); 818 int err, pnum, tries = 0, vol_id = vol->vol_id;
821 struct ubi_volume *vol = ubi->volumes[idx];
822 struct ubi_vid_hdr *vid_hdr; 819 struct ubi_vid_hdr *vid_hdr;
823 uint32_t crc; 820 uint32_t crc;
824 821
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index 41ff74c60e14..d397219238d3 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -129,8 +129,7 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len,
129 if (to_read > total_read) 129 if (to_read > total_read)
130 to_read = total_read; 130 to_read = total_read;
131 131
132 err = ubi_eba_read_leb(ubi, vol->vol_id, lnum, buf, offs, 132 err = ubi_eba_read_leb(ubi, vol, lnum, buf, offs, to_read, 0);
133 to_read, 0);
134 if (err) 133 if (err)
135 break; 134 break;
136 135
@@ -187,8 +186,8 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len,
187 if (to_write > total_written) 186 if (to_write > total_written)
188 to_write = total_written; 187 to_write = total_written;
189 188
190 err = ubi_eba_write_leb(ubi, vol->vol_id, lnum, buf, offs, 189 err = ubi_eba_write_leb(ubi, vol, lnum, buf, offs, to_write,
191 to_write, UBI_UNKNOWN); 190 UBI_UNKNOWN);
192 if (err) 191 if (err)
193 break; 192 break;
194 193
@@ -237,7 +236,7 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr)
237 return -EROFS; 236 return -EROFS;
238 237
239 for (i = 0; i < count; i++) { 238 for (i = 0; i < count; i++) {
240 err = ubi_eba_unmap_leb(ubi, vol->vol_id, lnum + i); 239 err = ubi_eba_unmap_leb(ubi, vol, lnum + i);
241 if (err) 240 if (err)
242 goto out_err; 241 goto out_err;
243 } 242 }
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 3bf2c951c2e5..c2fafe6fb2da 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -332,7 +332,7 @@ int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
332 if (len == 0) 332 if (len == 0)
333 return 0; 333 return 0;
334 334
335 err = ubi_eba_read_leb(ubi, vol_id, lnum, buf, offset, len, check); 335 err = ubi_eba_read_leb(ubi, vol, lnum, buf, offset, len, check);
336 if (err && err == -EBADMSG && vol->vol_type == UBI_STATIC_VOLUME) { 336 if (err && err == -EBADMSG && vol->vol_type == UBI_STATIC_VOLUME) {
337 ubi_warn("mark volume %d as corrupted", vol_id); 337 ubi_warn("mark volume %d as corrupted", vol_id);
338 vol->corrupted = 1; 338 vol->corrupted = 1;
@@ -399,7 +399,7 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
399 if (len == 0) 399 if (len == 0)
400 return 0; 400 return 0;
401 401
402 return ubi_eba_write_leb(ubi, vol_id, lnum, buf, offset, len, dtype); 402 return ubi_eba_write_leb(ubi, vol, lnum, buf, offset, len, dtype);
403} 403}
404EXPORT_SYMBOL_GPL(ubi_leb_write); 404EXPORT_SYMBOL_GPL(ubi_leb_write);
405 405
@@ -448,7 +448,7 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
448 if (len == 0) 448 if (len == 0)
449 return 0; 449 return 0;
450 450
451 return ubi_eba_atomic_leb_change(ubi, vol_id, lnum, buf, len, dtype); 451 return ubi_eba_atomic_leb_change(ubi, vol, lnum, buf, len, dtype);
452} 452}
453EXPORT_SYMBOL_GPL(ubi_leb_change); 453EXPORT_SYMBOL_GPL(ubi_leb_change);
454 454
@@ -481,7 +481,7 @@ int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum)
481 if (vol->upd_marker) 481 if (vol->upd_marker)
482 return -EBADF; 482 return -EBADF;
483 483
484 err = ubi_eba_unmap_leb(ubi, vol_id, lnum); 484 err = ubi_eba_unmap_leb(ubi, vol, lnum);
485 if (err) 485 if (err)
486 return err; 486 return err;
487 487
@@ -542,7 +542,7 @@ int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum)
542 if (vol->upd_marker) 542 if (vol->upd_marker)
543 return -EBADF; 543 return -EBADF;
544 544
545 return ubi_eba_unmap_leb(ubi, vol_id, lnum); 545 return ubi_eba_unmap_leb(ubi, vol, lnum);
546} 546}
547EXPORT_SYMBOL_GPL(ubi_leb_unmap); 547EXPORT_SYMBOL_GPL(ubi_leb_unmap);
548 548
@@ -587,7 +587,7 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype)
587 if (vol->eba_tbl[lnum] >= 0) 587 if (vol->eba_tbl[lnum] >= 0)
588 return -EBADMSG; 588 return -EBADMSG;
589 589
590 return ubi_eba_write_leb(ubi, vol_id, lnum, NULL, 0, 0, dtype); 590 return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype);
591} 591}
592EXPORT_SYMBOL_GPL(ubi_leb_map); 592EXPORT_SYMBOL_GPL(ubi_leb_map);
593 593
diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c
index 9e2338c8e2cf..93e052812012 100644
--- a/drivers/mtd/ubi/misc.c
+++ b/drivers/mtd/ubi/misc.c
@@ -79,7 +79,7 @@ int ubi_check_volume(struct ubi_device *ubi, int vol_id)
79 else 79 else
80 size = vol->usable_leb_size; 80 size = vol->usable_leb_size;
81 81
82 err = ubi_eba_read_leb(ubi, vol_id, i, buf, 0, size, 1); 82 err = ubi_eba_read_leb(ubi, vol, i, buf, 0, size, 1);
83 if (err) { 83 if (err) {
84 if (err == -EBADMSG) 84 if (err == -EBADMSG)
85 err = 1; 85 err = 1;
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 23875bf6aa3b..0a3a803dd22f 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -410,8 +410,8 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si);
410int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req); 410int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req);
411int ubi_remove_volume(struct ubi_volume_desc *desc); 411int ubi_remove_volume(struct ubi_volume_desc *desc);
412int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs); 412int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs);
413int ubi_add_volume(struct ubi_device *ubi, int vol_id); 413int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol);
414void ubi_free_volume(struct ubi_device *ubi, int vol_id); 414void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol);
415 415
416/* upd.c */ 416/* upd.c */
417int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes); 417int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes);
@@ -435,16 +435,17 @@ void ubi_gluebi_updated(struct ubi_volume *vol);
435#endif 435#endif
436 436
437/* eba.c */ 437/* eba.c */
438int ubi_eba_unmap_leb(struct ubi_device *ubi, int vol_id, int lnum); 438int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
439int ubi_eba_read_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf, 439 int lnum);
440 int offset, int len, int check); 440int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
441int ubi_eba_write_leb(struct ubi_device *ubi, int vol_id, int lnum, 441 void *buf, int offset, int len, int check);
442int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
442 const void *buf, int offset, int len, int dtype); 443 const void *buf, int offset, int len, int dtype);
443int ubi_eba_write_leb_st(struct ubi_device *ubi, int vol_id, int lnum, 444int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
444 const void *buf, int len, int dtype, 445 int lnum, const void *buf, int len, int dtype,
445 int used_ebs); 446 int used_ebs);
446int ubi_eba_atomic_leb_change(struct ubi_device *ubi, int vol_id, int lnum, 447int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
447 const void *buf, int len, int dtype); 448 int lnum, const void *buf, int len, int dtype);
448int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, 449int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,
449 struct ubi_vid_hdr *vid_hdr); 450 struct ubi_vid_hdr *vid_hdr);
450int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si); 451int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si);
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index 0efc586a8328..a95dcaa4a0c2 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -136,7 +136,7 @@ int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes)
136 136
137 /* Before updating - wipe out the volume */ 137 /* Before updating - wipe out the volume */
138 for (i = 0; i < vol->reserved_pebs; i++) { 138 for (i = 0; i < vol->reserved_pebs; i++) {
139 err = ubi_eba_unmap_leb(ubi, vol_id, i); 139 err = ubi_eba_unmap_leb(ubi, vol, i);
140 if (err) 140 if (err)
141 return err; 141 return err;
142 } 142 }
@@ -209,8 +209,7 @@ static int write_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf,
209 if (len != l) 209 if (len != l)
210 dbg_msg("skip last %d bytes (0xFF)", len - l); 210 dbg_msg("skip last %d bytes (0xFF)", len - l);
211 211
212 err = ubi_eba_write_leb(ubi, vol_id, lnum, buf, 0, l, 212 err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, l, UBI_UNKNOWN);
213 UBI_UNKNOWN);
214 } else { 213 } else {
215 /* 214 /*
216 * When writing static volume, and this is the last logical 215 * When writing static volume, and this is the last logical
@@ -222,7 +221,7 @@ static int write_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf,
222 * contain zeros, not random trash. 221 * contain zeros, not random trash.
223 */ 222 */
224 memset(buf + len, 0, vol->usable_leb_size - len); 223 memset(buf + len, 0, vol->usable_leb_size - len);
225 err = ubi_eba_write_leb_st(ubi, vol_id, lnum, buf, len, 224 err = ubi_eba_write_leb_st(ubi, vol, lnum, buf, len,
226 UBI_UNKNOWN, used_ebs); 225 UBI_UNKNOWN, used_ebs);
227 } 226 }
228 227
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 787ce9ec17ae..d2d12deead5c 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -417,7 +417,7 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
417 return err; 417 return err;
418 418
419 for (i = 0; i < vol->reserved_pebs; i++) { 419 for (i = 0; i < vol->reserved_pebs; i++) {
420 err = ubi_eba_unmap_leb(ubi, vol_id, i); 420 err = ubi_eba_unmap_leb(ubi, vol, i);
421 if (err) 421 if (err)
422 return err; 422 return err;
423 } 423 }
@@ -524,7 +524,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
524 524
525 if (pebs < 0) { 525 if (pebs < 0) {
526 for (i = 0; i < -pebs; i++) { 526 for (i = 0; i < -pebs; i++) {
527 err = ubi_eba_unmap_leb(ubi, vol_id, reserved_pebs + i); 527 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i);
528 if (err) 528 if (err)
529 goto out_acc; 529 goto out_acc;
530 } 530 }
@@ -573,17 +573,16 @@ out_free:
573/** 573/**
574 * ubi_add_volume - add volume. 574 * ubi_add_volume - add volume.
575 * @ubi: UBI device description object 575 * @ubi: UBI device description object
576 * @vol_id: volume ID 576 * @vol: volume description object
577 * 577 *
578 * This function adds an existin volume and initializes all its data 578 * This function adds an existin volume and initializes all its data
579 * structures. Returnes zero in case of success and a negative error code in 579 * structures. Returnes zero in case of success and a negative error code in
580 * case of failure. 580 * case of failure.
581 */ 581 */
582int ubi_add_volume(struct ubi_device *ubi, int vol_id) 582int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
583{ 583{
584 int err; 584 int err, vol_id = vol->vol_id;
585 dev_t dev; 585 dev_t dev;
586 struct ubi_volume *vol = ubi->volumes[vol_id];
587 586
588 dbg_msg("add volume %d", vol_id); 587 dbg_msg("add volume %d", vol_id);
589 ubi_dbg_dump_vol_info(vol); 588 ubi_dbg_dump_vol_info(vol);
@@ -634,22 +633,21 @@ out_cdev:
634/** 633/**
635 * ubi_free_volume - free volume. 634 * ubi_free_volume - free volume.
636 * @ubi: UBI device description object 635 * @ubi: UBI device description object
637 * @vol_id: volume ID 636 * @vol: volume description object
638 * 637 *
639 * This function frees all resources for volume @vol_id but does not remove it. 638 * This function frees all resources for volume @vol but does not remove it.
640 * Used only when the UBI device is detached. 639 * Used only when the UBI device is detached.
641 */ 640 */
642void ubi_free_volume(struct ubi_device *ubi, int vol_id) 641void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
643{ 642{
644 int err; 643 int err;
645 struct ubi_volume *vol = ubi->volumes[vol_id];
646 644
647 dbg_msg("free volume %d", vol_id); 645 dbg_msg("free volume %d", vol->vol_id);
648 ubi_assert(vol); 646 ubi_assert(vol);
649 647
650 vol->removed = 1; 648 vol->removed = 1;
651 err = ubi_destroy_gluebi(vol); 649 err = ubi_destroy_gluebi(vol);
652 ubi->volumes[vol_id] = NULL; 650 ubi->volumes[vol->vol_id] = NULL;
653 cdev_del(&vol->cdev); 651 cdev_del(&vol->cdev);
654 volume_sysfs_close(vol); 652 volume_sysfs_close(vol);
655} 653}
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 25b3bd61c7ec..3349c281bf9e 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -86,8 +86,10 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
86{ 86{
87 int i, err; 87 int i, err;
88 uint32_t crc; 88 uint32_t crc;
89 struct ubi_volume *layout_vol;
89 90
90 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots); 91 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots);
92 layout_vol = ubi->volumes[vol_id2idx(UBI_LAYOUT_VOL_ID)];
91 93
92 if (!vtbl_rec) 94 if (!vtbl_rec)
93 vtbl_rec = &empty_vtbl_record; 95 vtbl_rec = &empty_vtbl_record;
@@ -99,12 +101,12 @@ int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
99 mutex_lock(&ubi->vtbl_mutex); 101 mutex_lock(&ubi->vtbl_mutex);
100 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record)); 102 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record));
101 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) { 103 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {
102 err = ubi_eba_unmap_leb(ubi, UBI_LAYOUT_VOL_ID, i); 104 err = ubi_eba_unmap_leb(ubi, layout_vol, i);
103 if (err) { 105 if (err) {
104 mutex_unlock(&ubi->vtbl_mutex); 106 mutex_unlock(&ubi->vtbl_mutex);
105 return err; 107 return err;
106 } 108 }
107 err = ubi_eba_write_leb(ubi, UBI_LAYOUT_VOL_ID, i, ubi->vtbl, 0, 109 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,
108 ubi->vtbl_size, UBI_LONGTERM); 110 ubi->vtbl_size, UBI_LONGTERM);
109 if (err) { 111 if (err) {
110 mutex_unlock(&ubi->vtbl_mutex); 112 mutex_unlock(&ubi->vtbl_mutex);