···51 * @name: MTD device name or number string52 * @vid_hdr_offs: VID header offset53 */54-struct mtd_dev_param55-{56 char name[MTD_PARAM_LEN_MAX];57 int vid_hdr_offs;58};5960/* Numbers of elements set in the @mtd_dev_param array */61-static int mtd_devs = 0;6263/* MTD devices specification parameters */64static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES];···780 if (!ubi_devices[ubi_num])781 break;782 if (ubi_num == UBI_MAX_DEVICES) {783- dbg_err("only %d UBI devices may be created", UBI_MAX_DEVICES);0784 return -ENFILE;785 }786 } else {
···51 * @name: MTD device name or number string52 * @vid_hdr_offs: VID header offset53 */54+struct mtd_dev_param {055 char name[MTD_PARAM_LEN_MAX];56 int vid_hdr_offs;57};5859/* Numbers of elements set in the @mtd_dev_param array */60+static int mtd_devs;6162/* MTD devices specification parameters */63static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES];···781 if (!ubi_devices[ubi_num])782 break;783 if (ubi_num == UBI_MAX_DEVICES) {784+ dbg_err("only %d UBI devices may be created",785+ UBI_MAX_DEVICES);786 return -ENFILE;787 }788 } else {
···167 }168169 if (read != len && retries++ < UBI_IO_RETRIES) {170- dbg_io("error %d while reading %d bytes from PEB %d:%d, "171- "read only %zd bytes, retry",172 err, len, pnum, offset, read);173 yield();174 goto retry;···705706 if (hdr_crc != crc) {707 if (verbose) {708- ubi_warn("bad EC header CRC at PEB %d, calculated %#08x,"709- " read %#08x", pnum, crc, hdr_crc);710 ubi_dbg_dump_ec_hdr(ec_hdr);711 }712 return UBI_IO_BAD_EC_HDR;
···167 }168169 if (read != len && retries++ < UBI_IO_RETRIES) {170+ dbg_io("error %d while reading %d bytes from PEB %d:%d,"171+ " read only %zd bytes, retry",172 err, len, pnum, offset, read);173 yield();174 goto retry;···705706 if (hdr_crc != crc) {707 if (verbose) {708+ ubi_warn("bad EC header CRC at PEB %d, calculated "709+ "%#08x, read %#08x", pnum, crc, hdr_crc);710 ubi_dbg_dump_ec_hdr(ec_hdr);711 }712 return UBI_IO_BAD_EC_HDR;
+5-4
drivers/mtd/ubi/scan.c
···248 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum);249250 if (seb->sqnum == 0 && sqnum2 == 0) {251- long long abs, v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver);0252253 /*254 * UBI constantly increases the logical eraseblock version···753 * This function returns a zero if the physical eraseblock was successfully754 * handled and a negative error code in case of failure.755 */756-static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum)0757{758 long long uninitialized_var(ec);759 int err, bitflips = 0, vol_id, ec_corr = 0;···1303 if (err < 0) {1304 kfree(buf);1305 return err;1306- }1307- else if (err)1308 buf[pnum] = 1;1309 }1310
···248 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum);249250 if (seb->sqnum == 0 && sqnum2 == 0) {251+ long long abs;252+ long long v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver);253254 /*255 * UBI constantly increases the logical eraseblock version···752 * This function returns a zero if the physical eraseblock was successfully753 * handled and a negative error code in case of failure.754 */755+static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,756+ int pnum)757{758 long long uninitialized_var(ec);759 int err, bitflips = 0, vol_id, ec_corr = 0;···1301 if (err < 0) {1302 kfree(buf);1303 return err;1304+ } else if (err)01305 buf[pnum] = 1;1306 }1307
+2-1
drivers/mtd/ubi/ubi.h
···473 const void __user *buf, int count);474475/* misc.c */476-int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, int length);0477int ubi_check_volume(struct ubi_device *ubi, int vol_id);478void ubi_calculate_reserved(struct ubi_device *ubi);479
···473 const void __user *buf, int count);474475/* misc.c */476+int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf,477+ int length);478int ubi_check_volume(struct ubi_device *ubi, int vol_id);479void ubi_calculate_reserved(struct ubi_device *ubi);480
+5-3
drivers/mtd/ubi/upd.c
···39 */4041#include <linux/err.h>42-#include <asm/uaccess.h>43#include <asm/div64.h>44#include "ubi.h"45···246 return 0;247 }248249- err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len, UBI_UNKNOWN);0250 } else {251 /*252 * When writing static volume, and this is the last logical···419 if (vol->upd_received == vol->upd_bytes) {420 int len = ALIGN((int)vol->upd_bytes, ubi->min_io_size);421422- memset(vol->upd_buf + vol->upd_bytes, 0xFF, len - vol->upd_bytes);0423 len = ubi_calc_data_len(ubi, vol->upd_buf, len);424 err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum,425 vol->upd_buf, len, UBI_UNKNOWN);
···39 */4041#include <linux/err.h>42+#include <linux/uaccess.h>43#include <asm/div64.h>44#include "ubi.h"45···246 return 0;247 }248249+ err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len,250+ UBI_UNKNOWN);251 } else {252 /*253 * When writing static volume, and this is the last logical···418 if (vol->upd_received == vol->upd_bytes) {419 int len = ALIGN((int)vol->upd_bytes, ubi->min_io_size);420421+ memset(vol->upd_buf + vol->upd_bytes, 0xFF,422+ len - vol->upd_bytes);423 len = ubi_calc_data_len(ubi, vol->upd_buf, len);424 err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum,425 vol->upd_buf, len, UBI_UNKNOWN);
+2-2
drivers/mtd/ubi/vmt.c
···253 goto out_unlock;254 }255256- /* Calculate how many eraseblocks are requested */257 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;258 bytes = req->bytes;259 if (do_div(bytes, vol->usable_leb_size))···858859 if (alignment != vol->alignment || data_pad != vol->data_pad ||860 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||861- name_len!= vol->name_len || strncmp(name, vol->name, name_len)) {862 ubi_err("volume info is different");863 goto fail;864 }
···253 goto out_unlock;254 }255256+ /* Calculate how many eraseblocks are requested */257 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;258 bytes = req->bytes;259 if (do_div(bytes, vol->usable_leb_size))···858859 if (alignment != vol->alignment || data_pad != vol->data_pad ||860 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||861+ name_len != vol->name_len || strncmp(name, vol->name, name_len)) {862 ubi_err("volume info is different");863 goto fail;864 }
+6-6
drivers/mtd/ubi/vtbl.c
···461 if (!leb_corrupted[0]) {462 /* LEB 0 is OK */463 if (leb[1])464- leb_corrupted[1] = memcmp(leb[0], leb[1], ubi->vtbl_size);0465 if (leb_corrupted[1]) {466 ubi_warn("volume table copy #2 is corrupted");467 err = create_vtbl(ubi, si, 1, leb[0]);···860861out_free:862 vfree(ubi->vtbl);863- for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++)864- if (ubi->volumes[i]) {865- kfree(ubi->volumes[i]);866- ubi->volumes[i] = NULL;867- }868 return err;869}870
···461 if (!leb_corrupted[0]) {462 /* LEB 0 is OK */463 if (leb[1])464+ leb_corrupted[1] = memcmp(leb[0], leb[1],465+ ubi->vtbl_size);466 if (leb_corrupted[1]) {467 ubi_warn("volume table copy #2 is corrupted");468 err = create_vtbl(ubi, si, 1, leb[0]);···859860out_free:861 vfree(ubi->vtbl);862+ for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {863+ kfree(ubi->volumes[i]);864+ ubi->volumes[i] = NULL;865+ }0866 return err;867}868
+44-48
drivers/mtd/ubi/wl.c
···475 }476477 switch (dtype) {478- case UBI_LONGTERM:479- /*480- * For long term data we pick a physical eraseblock481- * with high erase counter. But the highest erase482- * counter we can pick is bounded by the the lowest483- * erase counter plus %WL_FREE_MAX_DIFF.484- */485- e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF);486- protect = LT_PROTECTION;487- break;488- case UBI_UNKNOWN:489- /*490- * For unknown data we pick a physical eraseblock with491- * medium erase counter. But we by no means can pick a492- * physical eraseblock with erase counter greater or493- * equivalent than the lowest erase counter plus494- * %WL_FREE_MAX_DIFF.495- */496- first = rb_entry(rb_first(&ubi->free),497- struct ubi_wl_entry, rb);498- last = rb_entry(rb_last(&ubi->free),499- struct ubi_wl_entry, rb);500501- if (last->ec - first->ec < WL_FREE_MAX_DIFF)502- e = rb_entry(ubi->free.rb_node,503- struct ubi_wl_entry, rb);504- else {505- medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2;506- e = find_wl_entry(&ubi->free, medium_ec);507- }508- protect = U_PROTECTION;509- break;510- case UBI_SHORTTERM:511- /*512- * For short term data we pick a physical eraseblock513- * with the lowest erase counter as we expect it will514- * be erased soon.515- */516- e = rb_entry(rb_first(&ubi->free),517- struct ubi_wl_entry, rb);518- protect = ST_PROTECTION;519- break;520- default:521- protect = 0;522- e = NULL;523- BUG();524 }525526 /*···579 * This function returns zero in case of success and a negative error code in580 * case of failure.581 */582-static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int torture)0583{584 int err;585 struct ubi_ec_hdr *ec_hdr;···1056 spin_unlock(&ubi->wl_lock);10571058 /*1059- * One more erase operation has happened, take care about protected1060- * physical eraseblocks.1061 */1062 check_protection_over(ubi);1063
···475 }476477 switch (dtype) {478+ case UBI_LONGTERM:479+ /*480+ * For long term data we pick a physical eraseblock with high481+ * erase counter. But the highest erase counter we can pick is482+ * bounded by the the lowest erase counter plus483+ * %WL_FREE_MAX_DIFF.484+ */485+ e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF);486+ protect = LT_PROTECTION;487+ break;488+ case UBI_UNKNOWN:489+ /*490+ * For unknown data we pick a physical eraseblock with medium491+ * erase counter. But we by no means can pick a physical492+ * eraseblock with erase counter greater or equivalent than the493+ * lowest erase counter plus %WL_FREE_MAX_DIFF.494+ */495+ first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, rb);496+ last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, rb);000497498+ if (last->ec - first->ec < WL_FREE_MAX_DIFF)499+ e = rb_entry(ubi->free.rb_node,500+ struct ubi_wl_entry, rb);501+ else {502+ medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2;503+ e = find_wl_entry(&ubi->free, medium_ec);504+ }505+ protect = U_PROTECTION;506+ break;507+ case UBI_SHORTTERM:508+ /*509+ * For short term data we pick a physical eraseblock with the510+ * lowest erase counter as we expect it will be erased soon.511+ */512+ e = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, rb);513+ protect = ST_PROTECTION;514+ break;515+ default:516+ protect = 0;517+ e = NULL;518+ BUG();00519 }520521 /*···584 * This function returns zero in case of success and a negative error code in585 * case of failure.586 */587+static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,588+ int torture)589{590 int err;591 struct ubi_ec_hdr *ec_hdr;···1060 spin_unlock(&ubi->wl_lock);10611062 /*1063+ * One more erase operation has happened, take care about1064+ * protected physical eraseblocks.1065 */1066 check_protection_over(ubi);1067
+8-8
include/mtd/ubi-user.h
···188 * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages.189 *190 * But in rare cases, if this optimizes things, the VID header may be placed to191- * a different offset. For example, the boot-loader might do things faster if the192- * VID header sits at the end of the first 2KiB NAND page with 4 sub-pages. As193- * the boot-loader would not normally need to read EC headers (unless it needs194- * UBI in RW mode), it might be faster to calculate ECC. This is weird example,195- * but it real-life example. So, in this example, @vid_hdr_offer would be196- * 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes197- * aligned, which is OK, as UBI is clever enough to realize this is 4th sub-page198- * of the first page and add needed padding.199 */200struct ubi_attach_req {201 int32_t ubi_num;
···188 * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages.189 *190 * But in rare cases, if this optimizes things, the VID header may be placed to191+ * a different offset. For example, the boot-loader might do things faster if192+ * the VID header sits at the end of the first 2KiB NAND page with 4 sub-pages.193+ * As the boot-loader would not normally need to read EC headers (unless it194+ * needs UBI in RW mode), it might be faster to calculate ECC. This is weird195+ * example, but it real-life example. So, in this example, @vid_hdr_offer would196+ * be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes197+ * aligned, which is OK, as UBI is clever enough to realize this is 4th198+ * sub-page of the first page and add needed padding.199 */200struct ubi_attach_req {201 int32_t ubi_num;