@@ -347,8 +347,6 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
lo = 0;
hi = bb->count;
if (bb->count) {
- int merged_sectors;
-
/* Find the last range that starts at-or-before 's' */
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
@@ -360,12 +358,19 @@ int badblocks_set(struct badblocks *bb, sector_t s, int sectors,
hi = mid;
}
- merged_sectors = badblocks_merge(bb, s, sectors, acknowledged,
- &lo, &hi, &changed);
- s += merged_sectors;
- sectors -= merged_sectors;
- if (sectors == 0)
+ while (sectors) {
+ int merged_sectors;
+
+ merged_sectors = badblocks_merge(bb, s, sectors, acknowledged,
+ &lo, &hi, &changed);
+ /* can't merge, break to create */
+ if (!merged_sectors)
+ break;
+
+ s += merged_sectors;
+ sectors -= merged_sectors;
badblocks_combine(bb, lo);
+ }
}
rv = badblocks_create(bb, s, sectors, hi, acknowledged, &changed);