|
42 | 42 |
|
43 | 43 | #include <linux/err.h> |
44 | 44 | #include <linux/crc32.h> |
| 45 | +#include <asm/div64.h> |
45 | 46 | #include "ubi.h" |
46 | 47 |
|
47 | 48 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID |
@@ -91,27 +92,6 @@ static int add_to_list(struct ubi_scan_info *si, int pnum, int ec, |
91 | 92 | return 0; |
92 | 93 | } |
93 | 94 |
|
94 | | -/** |
95 | | - * commit_to_mean_value - commit intermediate results to the final mean erase |
96 | | - * counter value. |
97 | | - * @si: scanning information |
98 | | - * |
99 | | - * This is a helper function which calculates partial mean erase counter mean |
100 | | - * value and adds it to the resulting mean value. As we can work only in |
101 | | - * integer arithmetic and we want to calculate the mean value of erase counter |
102 | | - * accurately, we first sum erase counter values in @si->ec_sum variable and |
103 | | - * count these components in @si->ec_count. If this temporary @si->ec_sum is |
104 | | - * going to overflow, we calculate the partial mean value |
105 | | - * (@si->ec_sum/@si->ec_count) and add it to @si->mean_ec. |
106 | | - */ |
107 | | -static void commit_to_mean_value(struct ubi_scan_info *si) |
108 | | -{ |
109 | | - si->ec_sum /= si->ec_count; |
110 | | - if (si->ec_sum % si->ec_count >= si->ec_count / 2) |
111 | | - si->mean_ec += 1; |
112 | | - si->mean_ec += si->ec_sum; |
113 | | -} |
114 | | - |
115 | 95 | /** |
116 | 96 | * validate_vid_hdr - check that volume identifier header is correct and |
117 | 97 | * consistent. |
@@ -901,15 +881,8 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum |
901 | 881 |
|
902 | 882 | adjust_mean_ec: |
903 | 883 | if (!ec_corr) { |
904 | | - if (si->ec_sum + ec < ec) { |
905 | | - commit_to_mean_value(si); |
906 | | - si->ec_sum = 0; |
907 | | - si->ec_count = 0; |
908 | | - } else { |
909 | | - si->ec_sum += ec; |
910 | | - si->ec_count += 1; |
911 | | - } |
912 | | - |
| 884 | + si->ec_sum += ec; |
| 885 | + si->ec_count += 1; |
913 | 886 | if (ec > si->max_ec) |
914 | 887 | si->max_ec = ec; |
915 | 888 | if (ec < si->min_ec) |
@@ -965,9 +938,11 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) |
965 | 938 |
|
966 | 939 | dbg_msg("scanning is finished"); |
967 | 940 |
|
968 | | - /* Finish mean erase counter calculations */ |
969 | | - if (si->ec_count) |
970 | | - commit_to_mean_value(si); |
| 941 | + /* Calculate mean erase counter */ |
| 942 | + if (si->ec_count) { |
| 943 | + do_div(si->ec_sum, si->ec_count); |
| 944 | + si->mean_ec = si->ec_sum; |
| 945 | + } |
971 | 946 |
|
972 | 947 | if (si->is_empty) |
973 | 948 | ubi_msg("empty MTD device detected"); |
|
0 commit comments