Pass volume description object to the EBA function which makes more sense, and EBA function do not have to find the volume description object by volume ID.
···249249250250 for (i = 0; i < ubi->vtbl_slots; i++)251251 if (ubi->volumes[i])252252- ubi_free_volume(ubi, i);252252+ ubi_free_volume(ubi, ubi->volumes[i]);253253}254254255255/**···300300301301 for (i = 0; i < ubi->vtbl_slots; i++)302302 if (ubi->volumes[i]) {303303- err = ubi_add_volume(ubi, i);303303+ err = ubi_add_volume(ubi, ubi->volumes[i]);304304 if (err) {305305 ubi_err("cannot add volume %d", i);306306 goto out_volumes;
···289289/**290290 * ubi_eba_unmap_leb - un-map logical eraseblock.291291 * @ubi: UBI device description object292292- * @vol_id: volume ID292292+ * @vol: volume description object293293 * @lnum: logical eraseblock number294294 *295295 * This function un-maps logical eraseblock @lnum and schedules corresponding296296 * physical eraseblock for erasure. Returns zero in case of success and a297297 * negative error code in case of failure.298298 */299299-int ubi_eba_unmap_leb(struct ubi_device *ubi, int vol_id, int lnum)299299+int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,300300+ int lnum)300301{301301- int idx = vol_id2idx(ubi, vol_id), err, pnum;302302- struct ubi_volume *vol = ubi->volumes[idx];302302+ int err, pnum, vol_id = vol->vol_id;303303304304 if (ubi->ro_mode)305305 return -EROFS;···326326/**327327 * ubi_eba_read_leb - read data.328328 * @ubi: UBI device description object329329- * @vol_id: volume ID329329+ * @vol: volume description object330330 * @lnum: logical eraseblock number331331 * @buf: buffer to store the read data332332 * @offset: offset from where to read···342342 * returned for any volume type if an ECC error was detected by the MTD device343343 * driver. Other negative error cored may be returned in case of other errors.344344 */345345-int ubi_eba_read_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf,346346- int offset, int len, int check)345345+int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,346346+ void *buf, int offset, int len, int check)347347{348348- int err, pnum, scrub = 0, idx = vol_id2idx(ubi, vol_id);348348+ int err, pnum, scrub = 0, vol_id = vol->vol_id;349349 struct ubi_vid_hdr *vid_hdr;350350- struct ubi_volume *vol = ubi->volumes[idx];351350 uint32_t uninitialized_var(crc);352351353352 err = leb_read_lock(ubi, vol_id, lnum);···554555/**555556 * ubi_eba_write_leb - write data to dynamic volume.556557 * @ubi: UBI device description object557557- * @vol_id: volume ID558558+ * @vol: volume description object558559 * @lnum: logical eraseblock number559560 * @buf: the data to write560561 * @offset: offset within the logical eraseblock where to write···562563 * @dtype: data type563564 *564565 * This function writes data to logical eraseblock @lnum of a dynamic volume565565- * @vol_id. Returns zero in case of success and a negative error code in case566566+ * @vol. Returns zero in case of success and a negative error code in case566567 * of failure. In case of error, it is possible that something was still567568 * written to the flash media, but may be some garbage.568569 */569569-int ubi_eba_write_leb(struct ubi_device *ubi, int vol_id, int lnum,570570+int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,570571 const void *buf, int offset, int len, int dtype)571572{572572- int idx = vol_id2idx(ubi, vol_id), err, pnum, tries = 0;573573- struct ubi_volume *vol = ubi->volumes[idx];573573+ int err, pnum, tries = 0, vol_id = vol->vol_id;574574 struct ubi_vid_hdr *vid_hdr;575575576576 if (ubi->ro_mode)···588590 if (err) {589591 ubi_warn("failed to write data to PEB %d", pnum);590592 if (err == -EIO && ubi->bad_allowed)591591- err = recover_peb(ubi, pnum, vol_id, lnum, buf, offset, len);593593+ err = recover_peb(ubi, pnum, vol_id, lnum, buf,594594+ offset, len);592595 if (err)593596 ubi_ro_mode(ubi);594597 }···677678/**678679 * ubi_eba_write_leb_st - write data to static volume.679680 * @ubi: UBI device description object680680- * @vol_id: volume ID681681+ * @vol: volume description object681682 * @lnum: logical eraseblock number682683 * @buf: data to write683684 * @len: how many bytes to write···685686 * @used_ebs: how many logical eraseblocks will this volume contain686687 *687688 * This function writes data to logical eraseblock @lnum of static volume688688- * @vol_id. The @used_ebs argument should contain total number of logical689689+ * @vol. The @used_ebs argument should contain total number of logical689690 * eraseblock in this static volume.690691 *691692 * When writing to the last logical eraseblock, the @len argument doesn't have···697698 * volumes. This function returns zero in case of success and a negative error698699 * code in case of failure.699700 */700700-int ubi_eba_write_leb_st(struct ubi_device *ubi, int vol_id, int lnum,701701- const void *buf, int len, int dtype, int used_ebs)701701+int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,702702+ int lnum, const void *buf, int len, int dtype,703703+ int used_ebs)702704{703703- int err, pnum, tries = 0, data_size = len;704704- int idx = vol_id2idx(ubi, vol_id);705705- struct ubi_volume *vol = ubi->volumes[idx];705705+ int err, pnum, tries = 0, data_size = len, vol_id = vol->vol_id;706706 struct ubi_vid_hdr *vid_hdr;707707 uint32_t crc;708708···797799/*798800 * ubi_eba_atomic_leb_change - change logical eraseblock atomically.799801 * @ubi: UBI device description object800800- * @vol_id: volume ID802802+ * @vol: volume escription object801803 * @lnum: logical eraseblock number802804 * @buf: data to write803805 * @len: how many bytes to write···812814 * UBI reserves one LEB for the "atomic LEB change" operation, so only one813815 * LEB change may be done at a time. This is ensured by @ubi->alc_mutex.814816 */815815-int ubi_eba_atomic_leb_change(struct ubi_device *ubi, int vol_id, int lnum,816816- const void *buf, int len, int dtype)817817+int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,818818+ int lnum, const void *buf, int len, int dtype)817819{818818- int err, pnum, tries = 0, idx = vol_id2idx(ubi, vol_id);819819- struct ubi_volume *vol = ubi->volumes[idx];820820+ int err, pnum, tries = 0, vol_id = vol->vol_id;820821 struct ubi_vid_hdr *vid_hdr;821822 uint32_t crc;822823
···7979 else8080 size = vol->usable_leb_size;81818282- err = ubi_eba_read_leb(ubi, vol_id, i, buf, 0, size, 1);8282+ err = ubi_eba_read_leb(ubi, vol, i, buf, 0, size, 1);8383 if (err) {8484 if (err == -EBADMSG)8585 err = 1;
+11-10
drivers/mtd/ubi/ubi.h
···410410int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req);411411int ubi_remove_volume(struct ubi_volume_desc *desc);412412int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs);413413-int ubi_add_volume(struct ubi_device *ubi, int vol_id);414414-void ubi_free_volume(struct ubi_device *ubi, int vol_id);413413+int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol);414414+void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol);415415416416/* upd.c */417417int ubi_start_update(struct ubi_device *ubi, int vol_id, long long bytes);···435435#endif436436437437/* eba.c */438438-int ubi_eba_unmap_leb(struct ubi_device *ubi, int vol_id, int lnum);439439-int ubi_eba_read_leb(struct ubi_device *ubi, int vol_id, int lnum, void *buf,440440- int offset, int len, int check);441441-int ubi_eba_write_leb(struct ubi_device *ubi, int vol_id, int lnum,438438+int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,439439+ int lnum);440440+int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,441441+ void *buf, int offset, int len, int check);442442+int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,442443 const void *buf, int offset, int len, int dtype);443443-int ubi_eba_write_leb_st(struct ubi_device *ubi, int vol_id, int lnum,444444- const void *buf, int len, int dtype,444444+int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,445445+ int lnum, const void *buf, int len, int dtype,445446 int used_ebs);446446-int ubi_eba_atomic_leb_change(struct ubi_device *ubi, int vol_id, int lnum,447447- const void *buf, int len, int dtype);447447+int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,448448+ int lnum, const void *buf, int len, int dtype);448449int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to,449450 struct ubi_vid_hdr *vid_hdr);450451int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si);
+3-4
drivers/mtd/ubi/upd.c
···136136137137 /* Before updating - wipe out the volume */138138 for (i = 0; i < vol->reserved_pebs; i++) {139139- err = ubi_eba_unmap_leb(ubi, vol_id, i);139139+ err = ubi_eba_unmap_leb(ubi, vol, i);140140 if (err)141141 return err;142142 }···209209 if (len != l)210210 dbg_msg("skip last %d bytes (0xFF)", len - l);211211212212- err = ubi_eba_write_leb(ubi, vol_id, lnum, buf, 0, l,213213- UBI_UNKNOWN);212212+ err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, l, UBI_UNKNOWN);214213 } else {215214 /*216215 * When writing static volume, and this is the last logical···221222 * contain zeros, not random trash.222223 */223224 memset(buf + len, 0, vol->usable_leb_size - len);224224- err = ubi_eba_write_leb_st(ubi, vol_id, lnum, buf, len,225225+ err = ubi_eba_write_leb_st(ubi, vol, lnum, buf, len,225226 UBI_UNKNOWN, used_ebs);226227 }227228
+10-12
drivers/mtd/ubi/vmt.c
···417417 return err;418418419419 for (i = 0; i < vol->reserved_pebs; i++) {420420- err = ubi_eba_unmap_leb(ubi, vol_id, i);420420+ err = ubi_eba_unmap_leb(ubi, vol, i);421421 if (err)422422 return err;423423 }···524524525525 if (pebs < 0) {526526 for (i = 0; i < -pebs; i++) {527527- err = ubi_eba_unmap_leb(ubi, vol_id, reserved_pebs + i);527527+ err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i);528528 if (err)529529 goto out_acc;530530 }···573573/**574574 * ubi_add_volume - add volume.575575 * @ubi: UBI device description object576576- * @vol_id: volume ID576576+ * @vol: volume description object577577 *578578 * This function adds an existin volume and initializes all its data579579 * structures. Returnes zero in case of success and a negative error code in580580 * case of failure.581581 */582582-int ubi_add_volume(struct ubi_device *ubi, int vol_id)582582+int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)583583{584584- int err;584584+ int err, vol_id = vol->vol_id;585585 dev_t dev;586586- struct ubi_volume *vol = ubi->volumes[vol_id];587586588587 dbg_msg("add volume %d", vol_id);589588 ubi_dbg_dump_vol_info(vol);···633634/**634635 * ubi_free_volume - free volume.635636 * @ubi: UBI device description object636636- * @vol_id: volume ID637637+ * @vol: volume description object637638 *638638- * This function frees all resources for volume @vol_id but does not remove it.639639+ * This function frees all resources for volume @vol but does not remove it.639640 * Used only when the UBI device is detached.640641 */641641-void ubi_free_volume(struct ubi_device *ubi, int vol_id)642642+void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)642643{643644 int err;644644- struct ubi_volume *vol = ubi->volumes[vol_id];645645646646- dbg_msg("free volume %d", vol_id);646646+ dbg_msg("free volume %d", vol->vol_id);647647 ubi_assert(vol);648648649649 vol->removed = 1;650650 err = ubi_destroy_gluebi(vol);651651- ubi->volumes[vol_id] = NULL;651651+ ubi->volumes[vol->vol_id] = NULL;652652 cdev_del(&vol->cdev);653653 volume_sysfs_close(vol);654654}
+4-2
drivers/mtd/ubi/vtbl.c
···8686{8787 int i, err;8888 uint32_t crc;8989+ struct ubi_volume *layout_vol;89909091 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots);9292+ layout_vol = ubi->volumes[vol_id2idx(UBI_LAYOUT_VOL_ID)];91939294 if (!vtbl_rec)9395 vtbl_rec = &empty_vtbl_record;···10199 mutex_lock(&ubi->vtbl_mutex);102100 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record));103101 for (i = 0; i < UBI_LAYOUT_VOLUME_EBS; i++) {104104- err = ubi_eba_unmap_leb(ubi, UBI_LAYOUT_VOL_ID, i);102102+ err = ubi_eba_unmap_leb(ubi, layout_vol, i);105103 if (err) {106104 mutex_unlock(&ubi->vtbl_mutex);107105 return err;108106 }109109- err = ubi_eba_write_leb(ubi, UBI_LAYOUT_VOL_ID, i, ubi->vtbl, 0,107107+ err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0,110108 ubi->vtbl_size, UBI_LONGTERM);111109 if (err) {112110 mutex_unlock(&ubi->vtbl_mutex);