···5151 * @name: MTD device name or number string5252 * @vid_hdr_offs: VID header offset5353 */5454-struct mtd_dev_param5555-{5454+struct mtd_dev_param {5655 char name[MTD_PARAM_LEN_MAX];5756 int vid_hdr_offs;5857};59586059/* Numbers of elements set in the @mtd_dev_param array */6161-static int mtd_devs = 0;6060+static int mtd_devs;62616362/* MTD devices specification parameters */6463static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES];···780781 if (!ubi_devices[ubi_num])781782 break;782783 if (ubi_num == UBI_MAX_DEVICES) {783783- dbg_err("only %d UBI devices may be created", UBI_MAX_DEVICES);784784+ dbg_err("only %d UBI devices may be created",785785+ UBI_MAX_DEVICES);784786 return -ENFILE;785787 }786788 } else {
···167167 }168168169169 if (read != len && retries++ < UBI_IO_RETRIES) {170170- dbg_io("error %d while reading %d bytes from PEB %d:%d, "171171- "read only %zd bytes, retry",170170+ dbg_io("error %d while reading %d bytes from PEB %d:%d,"171171+ " read only %zd bytes, retry",172172 err, len, pnum, offset, read);173173 yield();174174 goto retry;···705705706706 if (hdr_crc != crc) {707707 if (verbose) {708708- ubi_warn("bad EC header CRC at PEB %d, calculated %#08x,"709709- " read %#08x", pnum, crc, hdr_crc);708708+ ubi_warn("bad EC header CRC at PEB %d, calculated "709709+ "%#08x, read %#08x", pnum, crc, hdr_crc);710710 ubi_dbg_dump_ec_hdr(ec_hdr);711711 }712712 return UBI_IO_BAD_EC_HDR;
+5-4
drivers/mtd/ubi/scan.c
···248248 unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum);249249250250 if (seb->sqnum == 0 && sqnum2 == 0) {251251- long long abs, v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver);251251+ long long abs;252252+ long long v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver);252253253254 /*254255 * UBI constantly increases the logical eraseblock version···753752 * This function returns a zero if the physical eraseblock was successfully754753 * handled and a negative error code in case of failure.755754 */756756-static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum)755755+static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,756756+ int pnum)757757{758758 long long uninitialized_var(ec);759759 int err, bitflips = 0, vol_id, ec_corr = 0;···13031301 if (err < 0) {13041302 kfree(buf);13051303 return err;13061306- }13071307- else if (err)13041304+ } else if (err)13081305 buf[pnum] = 1;13091306 }13101307
+2-1
drivers/mtd/ubi/ubi.h
···473473 const void __user *buf, int count);474474475475/* misc.c */476476-int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, int length);476476+int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf,477477+ int length);477478int ubi_check_volume(struct ubi_device *ubi, int vol_id);478479void ubi_calculate_reserved(struct ubi_device *ubi);479480
+5-3
drivers/mtd/ubi/upd.c
···3939 */40404141#include <linux/err.h>4242-#include <asm/uaccess.h>4242+#include <linux/uaccess.h>4343#include <asm/div64.h>4444#include "ubi.h"4545···246246 return 0;247247 }248248249249- err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len, UBI_UNKNOWN);249249+ err = ubi_eba_write_leb(ubi, vol, lnum, buf, 0, len,250250+ UBI_UNKNOWN);250251 } else {251252 /*252253 * When writing static volume, and this is the last logical···419418 if (vol->upd_received == vol->upd_bytes) {420419 int len = ALIGN((int)vol->upd_bytes, ubi->min_io_size);421420422422- memset(vol->upd_buf + vol->upd_bytes, 0xFF, len - vol->upd_bytes);421421+ memset(vol->upd_buf + vol->upd_bytes, 0xFF,422422+ len - vol->upd_bytes);423423 len = ubi_calc_data_len(ubi, vol->upd_buf, len);424424 err = ubi_eba_atomic_leb_change(ubi, vol, vol->ch_lnum,425425 vol->upd_buf, len, UBI_UNKNOWN);
+2-2
drivers/mtd/ubi/vmt.c
···253253 goto out_unlock;254254 }255255256256- /* Calculate how many eraseblocks are requested */256256+ /* Calculate how many eraseblocks are requested */257257 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;258258 bytes = req->bytes;259259 if (do_div(bytes, vol->usable_leb_size))···858858859859 if (alignment != vol->alignment || data_pad != vol->data_pad ||860860 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||861861- name_len!= vol->name_len || strncmp(name, vol->name, name_len)) {861861+ name_len != vol->name_len || strncmp(name, vol->name, name_len)) {862862 ubi_err("volume info is different");863863 goto fail;864864 }
+6-6
drivers/mtd/ubi/vtbl.c
···461461 if (!leb_corrupted[0]) {462462 /* LEB 0 is OK */463463 if (leb[1])464464- leb_corrupted[1] = memcmp(leb[0], leb[1], ubi->vtbl_size);464464+ leb_corrupted[1] = memcmp(leb[0], leb[1],465465+ ubi->vtbl_size);465466 if (leb_corrupted[1]) {466467 ubi_warn("volume table copy #2 is corrupted");467468 err = create_vtbl(ubi, si, 1, leb[0]);···860859861860out_free:862861 vfree(ubi->vtbl);863863- for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++)864864- if (ubi->volumes[i]) {865865- kfree(ubi->volumes[i]);866866- ubi->volumes[i] = NULL;867867- }862862+ for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {863863+ kfree(ubi->volumes[i]);864864+ ubi->volumes[i] = NULL;865865+ }868866 return err;869867}870868
+44-48
drivers/mtd/ubi/wl.c
···475475 }476476477477 switch (dtype) {478478- case UBI_LONGTERM:479479- /*480480- * For long term data we pick a physical eraseblock481481- * with high erase counter. But the highest erase482482- * counter we can pick is bounded by the the lowest483483- * erase counter plus %WL_FREE_MAX_DIFF.484484- */485485- e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF);486486- protect = LT_PROTECTION;487487- break;488488- case UBI_UNKNOWN:489489- /*490490- * For unknown data we pick a physical eraseblock with491491- * medium erase counter. But we by no means can pick a492492- * physical eraseblock with erase counter greater or493493- * equivalent than the lowest erase counter plus494494- * %WL_FREE_MAX_DIFF.495495- */496496- first = rb_entry(rb_first(&ubi->free),497497- struct ubi_wl_entry, rb);498498- last = rb_entry(rb_last(&ubi->free),499499- struct ubi_wl_entry, rb);478478+ case UBI_LONGTERM:479479+ /*480480+ * For long term data we pick a physical eraseblock with high481481+ * erase counter. But the highest erase counter we can pick is482482+ * bounded by the the lowest erase counter plus483483+ * %WL_FREE_MAX_DIFF.484484+ */485485+ e = find_wl_entry(&ubi->free, WL_FREE_MAX_DIFF);486486+ protect = LT_PROTECTION;487487+ break;488488+ case UBI_UNKNOWN:489489+ /*490490+ * For unknown data we pick a physical eraseblock with medium491491+ * erase counter. But we by no means can pick a physical492492+ * eraseblock with erase counter greater or equivalent than the493493+ * lowest erase counter plus %WL_FREE_MAX_DIFF.494494+ */495495+ first = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, rb);496496+ last = rb_entry(rb_last(&ubi->free), struct ubi_wl_entry, rb);500497501501- if (last->ec - first->ec < WL_FREE_MAX_DIFF)502502- e = rb_entry(ubi->free.rb_node,503503- struct ubi_wl_entry, rb);504504- else {505505- medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2;506506- e = find_wl_entry(&ubi->free, medium_ec);507507- }508508- protect = U_PROTECTION;509509- break;510510- case UBI_SHORTTERM:511511- /*512512- * For short term data we pick a physical eraseblock513513- * with the lowest erase counter as we expect it will514514- * be erased soon.515515- */516516- e = rb_entry(rb_first(&ubi->free),517517- struct ubi_wl_entry, rb);518518- protect = ST_PROTECTION;519519- break;520520- default:521521- protect = 0;522522- e = NULL;523523- BUG();498498+ if (last->ec - first->ec < WL_FREE_MAX_DIFF)499499+ e = rb_entry(ubi->free.rb_node,500500+ struct ubi_wl_entry, rb);501501+ else {502502+ medium_ec = (first->ec + WL_FREE_MAX_DIFF)/2;503503+ e = find_wl_entry(&ubi->free, medium_ec);504504+ }505505+ protect = U_PROTECTION;506506+ break;507507+ case UBI_SHORTTERM:508508+ /*509509+ * For short term data we pick a physical eraseblock with the510510+ * lowest erase counter as we expect it will be erased soon.511511+ */512512+ e = rb_entry(rb_first(&ubi->free), struct ubi_wl_entry, rb);513513+ protect = ST_PROTECTION;514514+ break;515515+ default:516516+ protect = 0;517517+ e = NULL;518518+ BUG();524519 }525520526521 /*···579584 * This function returns zero in case of success and a negative error code in580585 * case of failure.581586 */582582-static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, int torture)587587+static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,588588+ int torture)583589{584590 int err;585591 struct ubi_ec_hdr *ec_hdr;···10561060 spin_unlock(&ubi->wl_lock);1057106110581062 /*10591059- * One more erase operation has happened, take care about protected10601060- * physical eraseblocks.10631063+ * One more erase operation has happened, take care about10641064+ * protected physical eraseblocks.10611065 */10621066 check_protection_over(ubi);10631067
+8-8
include/mtd/ubi-user.h
···188188 * it will be 512 in case of a 2KiB page NAND flash with 4 512-byte sub-pages.189189 *190190 * But in rare cases, if this optimizes things, the VID header may be placed to191191- * a different offset. For example, the boot-loader might do things faster if the192192- * VID header sits at the end of the first 2KiB NAND page with 4 sub-pages. As193193- * the boot-loader would not normally need to read EC headers (unless it needs194194- * UBI in RW mode), it might be faster to calculate ECC. This is weird example,195195- * but it real-life example. So, in this example, @vid_hdr_offer would be196196- * 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes197197- * aligned, which is OK, as UBI is clever enough to realize this is 4th sub-page198198- * of the first page and add needed padding.191191+ * a different offset. For example, the boot-loader might do things faster if192192+ * the VID header sits at the end of the first 2KiB NAND page with 4 sub-pages.193193+ * As the boot-loader would not normally need to read EC headers (unless it194194+ * needs UBI in RW mode), it might be faster to calculate ECC. This is weird195195+ * example, but it real-life example. So, in this example, @vid_hdr_offer would196196+ * be 2KiB-64 bytes = 1984. Note, that this position is not even 512-bytes197197+ * aligned, which is OK, as UBI is clever enough to realize this is 4th198198+ * sub-page of the first page and add needed padding.199199 */200200struct ubi_attach_req {201201 int32_t ubi_num;