UBI: fix checkpatch.pl errors and warnings
[deliverable/linux.git] / drivers / mtd / ubi / scan.c
index c7b0afc9d2808e13b64ce2fae7d6755b2c99041e..0bb7488862d2a8e7abb8b33aaceb6655a3a0fb20 100644 (file)
@@ -19,9 +19,9 @@
  */
 
 /*
- * UBI scanning unit.
+ * UBI scanning sub-system.
  *
- * This unit is responsible for scanning the flash media, checking UBI
+ * This sub-system is responsible for scanning the flash media, checking UBI
  * headers and providing complete information about the UBI flash image.
  *
  * The scanning information is represented by a &struct ubi_scan_info' object.
@@ -42,6 +42,7 @@
 
 #include <linux/err.h>
 #include <linux/crc32.h>
+#include <asm/div64.h>
 #include "ubi.h"
 
 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
@@ -91,27 +92,6 @@ static int add_to_list(struct ubi_scan_info *si, int pnum, int ec,
        return 0;
 }
 
-/**
- * commit_to_mean_value - commit intermediate results to the final mean erase
- * counter value.
- * @si: scanning information
- *
- * This is a helper function which calculates partial mean erase counter mean
- * value and adds it to the resulting mean value. As we can work only in
- * integer arithmetic and we want to calculate the mean value of erase counter
- * accurately, we first sum erase counter values in @si->ec_sum variable and
- * count these components in @si->ec_count. If this temporary @si->ec_sum is
- * going to overflow, we calculate the partial mean value
- * (@si->ec_sum/@si->ec_count) and add it to @si->mean_ec.
- */
-static void commit_to_mean_value(struct ubi_scan_info *si)
-{
-       si->ec_sum /= si->ec_count;
-       if (si->ec_sum % si->ec_count >= si->ec_count / 2)
-               si->mean_ec += 1;
-       si->mean_ec += si->ec_sum;
-}
-
 /**
  * validate_vid_hdr - check that volume identifier header is correct and
  * consistent.
@@ -123,7 +103,7 @@ static void commit_to_mean_value(struct ubi_scan_info *si)
  * non-zero if an inconsistency was found and zero if not.
  *
  * Note, UBI does sanity check of everything it reads from the flash media.
- * Most of the checks are done in the I/O unit. Here we check that the
+ * Most of the checks are done in the I/O sub-system. Here we check that the
  * information in the VID header is consistent to the information in other VID
  * headers of the same volume.
  */
@@ -268,7 +248,8 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
        unsigned long long sqnum2 = be64_to_cpu(vid_hdr->sqnum);
 
        if (seb->sqnum == 0 && sqnum2 == 0) {
-               long long abs, v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver);
+               long long abs;
+               long long v1 = seb->leb_ver, v2 = be32_to_cpu(vid_hdr->leb_ver);
 
                /*
                 * UBI constantly increases the logical eraseblock version
@@ -276,8 +257,8 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
                 * that versions that are close to %0xFFFFFFFF are less then
                 * versions that are close to %0.
                 *
-                * The UBI WL unit guarantees that the number of pending tasks
-                * is not greater then %0x7FFFFFFF. So, if the difference
+                * The UBI WL sub-system guarantees that the number of pending
+                * tasks is not greater then %0x7FFFFFFF. So, if the difference
                 * between any two versions is greater or equivalent to
                 * %0x7FFFFFFF, there was an overflow and the logical
                 * eraseblock with lower version is actually newer then the one
@@ -286,9 +267,14 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb,
                 * FIXME: but this is anyway obsolete and will be removed at
                 * some point.
                 */
-
                dbg_bld("using old crappy leb_ver stuff");
 
+               if (v1 == v2) {
+                       ubi_err("PEB %d and PEB %d have the same version %lld",
+                               seb->pnum, pnum, v1);
+                       return -EINVAL;
+               }
+
                abs = v1 - v2;
                if (abs < 0)
                        abs = -abs;
@@ -390,7 +376,6 @@ out_free_buf:
        vfree(buf);
 out_free_vidh:
        ubi_free_vid_hdr(ubi, vh);
-       ubi_assert(err < 0);
        return err;
 }
 
@@ -661,9 +646,9 @@ void ubi_scan_rm_volume(struct ubi_scan_info *si, struct ubi_scan_volume *sv)
  *
  * This function erases physical eraseblock 'pnum', and writes the erase
  * counter header to it. This function should only be used on UBI device
- * initialization stages, when the EBA unit had not been yet initialized. This
- * function returns zero in case of success and a negative error code in case
- * of failure.
+ * initialization stages, when the EBA sub-system had not been yet initialized.
+ * This function returns zero in case of success and a negative error code in
+ * case of failure.
  */
 int ubi_scan_erase_peb(struct ubi_device *ubi, const struct ubi_scan_info *si,
                       int pnum, int ec)
@@ -703,9 +688,10 @@ out_free:
  * @si: scanning information
  *
  * This function returns a free physical eraseblock. It is supposed to be
- * called on the UBI initialization stages when the wear-leveling unit is not
- * initialized yet. This function picks a physical eraseblocks from one of the
- * lists, writes the EC header if it is needed, and removes it from the list.
+ * called on the UBI initialization stages when the wear-leveling sub-system is
+ * not initialized yet. This function picks a physical eraseblocks from one of
+ * the lists, writes the EC header if it is needed, and removes it from the
+ * list.
  *
  * This function returns scanning physical eraseblock information in case of
  * success and an error code in case of failure.
@@ -767,9 +753,10 @@ struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi,
  * This function returns a zero if the physical eraseblock was successfully
  * handled and a negative error code in case of failure.
  */
-static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum)
+static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
+                     int pnum)
 {
-       long long ec;
+       long long uninitialized_var(ec);
        int err, bitflips = 0, vol_id, ec_corr = 0;
 
        dbg_bld("scan PEB %d", pnum);
@@ -780,8 +767,9 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum
                return err;
        else if (err) {
                /*
-                * FIXME: this is actually duty of the I/O unit to initialize
-                * this, but MTD does not provide enough information.
+                * FIXME: this is actually duty of the I/O sub-system to
+                * initialize this, but MTD does not provide enough
+                * information.
                 */
                si->bad_peb_count += 1;
                return 0;
@@ -854,7 +842,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum
        }
 
        vol_id = be32_to_cpu(vidh->vol_id);
-       if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOL_ID) {
+       if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOLUME_ID) {
                int lnum = be32_to_cpu(vidh->lnum);
 
                /* Unsupported internal volume */
@@ -897,15 +885,8 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum
 
 adjust_mean_ec:
        if (!ec_corr) {
-               if (si->ec_sum + ec < ec) {
-                       commit_to_mean_value(si);
-                       si->ec_sum = 0;
-                       si->ec_count = 0;
-               } else {
-                       si->ec_sum += ec;
-                       si->ec_count += 1;
-               }
-
+               si->ec_sum += ec;
+               si->ec_count += 1;
                if (ec > si->max_ec)
                        si->max_ec = ec;
                if (ec < si->min_ec)
@@ -953,7 +934,7 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
        for (pnum = 0; pnum < ubi->peb_count; pnum++) {
                cond_resched();
 
-               dbg_msg("process PEB %d", pnum);
+               dbg_gen("process PEB %d", pnum);
                err = process_eb(ubi, si, pnum);
                if (err < 0)
                        goto out_vidh;
@@ -961,9 +942,11 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
 
        dbg_msg("scanning is finished");
 
-       /* Finish mean erase counter calculations */
-       if (si->ec_count)
-               commit_to_mean_value(si);
+       /* Calculate mean erase counter */
+       if (si->ec_count) {
+               do_div(si->ec_sum, si->ec_count);
+               si->mean_ec = si->ec_sum;
+       }
 
        if (si->is_empty)
                ubi_msg("empty MTD device detected");
@@ -1320,8 +1303,7 @@ static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
                if (err < 0) {
                        kfree(buf);
                        return err;
-               }
-               else if (err)
+               } else if (err)
                        buf[pnum] = 1;
        }
 
This page took 0.028667 seconds and 5 git commands to generate.