ocfs2: correctly use ocfs2_find_next_zero_bit()
If no bits are zero, ocfs2_find_next_zero_bit() will return max size, so check the return value with -1 is meaningless. Correct this usage and cleanup the code. Link: https://lkml.kernel.org/r/20240314021713.240796-1-joseph.qi@linux.alibaba.com Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com> Reviewed-by: Heming Zhao <heming.zhao@suse.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Jun Piao <piaojun@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
0bbac3facb
commit
30dd3478c3
3 changed files with 9 additions and 18 deletions
|
@ -863,14 +863,8 @@ static int ocfs2_local_alloc_find_clear_bits(struct ocfs2_super *osb,
|
||||||
|
|
||||||
numfound = bitoff = startoff = 0;
|
numfound = bitoff = startoff = 0;
|
||||||
left = le32_to_cpu(alloc->id1.bitmap1.i_total);
|
left = le32_to_cpu(alloc->id1.bitmap1.i_total);
|
||||||
while ((bitoff = ocfs2_find_next_zero_bit(bitmap, left, startoff)) != -1) {
|
while ((bitoff = ocfs2_find_next_zero_bit(bitmap, left, startoff)) <
|
||||||
if (bitoff == left) {
|
left) {
|
||||||
/* mlog(0, "bitoff (%d) == left", bitoff); */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* mlog(0, "Found a zero: bitoff = %d, startoff = %d, "
|
|
||||||
"numfound = %d\n", bitoff, startoff, numfound);*/
|
|
||||||
|
|
||||||
/* Ok, we found a zero bit... is it contig. or do we
|
/* Ok, we found a zero bit... is it contig. or do we
|
||||||
* start over?*/
|
* start over?*/
|
||||||
if (bitoff == startoff) {
|
if (bitoff == startoff) {
|
||||||
|
@ -976,9 +970,9 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
|
||||||
start = count = 0;
|
start = count = 0;
|
||||||
left = le32_to_cpu(alloc->id1.bitmap1.i_total);
|
left = le32_to_cpu(alloc->id1.bitmap1.i_total);
|
||||||
|
|
||||||
while ((bit_off = ocfs2_find_next_zero_bit(bitmap, left, start))
|
while ((bit_off = ocfs2_find_next_zero_bit(bitmap, left, start)) <
|
||||||
!= -1) {
|
left) {
|
||||||
if ((bit_off < left) && (bit_off == start)) {
|
if (bit_off == start) {
|
||||||
count++;
|
count++;
|
||||||
start++;
|
start++;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1002,8 +996,7 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bit_off >= left)
|
|
||||||
break;
|
|
||||||
count = 1;
|
count = 1;
|
||||||
start = bit_off + 1;
|
start = bit_off + 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -414,7 +414,7 @@ static int ocfs2_resmap_find_free_bits(struct ocfs2_reservation_map *resmap,
|
||||||
|
|
||||||
start = search_start;
|
start = search_start;
|
||||||
while ((offset = ocfs2_find_next_zero_bit(bitmap, resmap->m_bitmap_len,
|
while ((offset = ocfs2_find_next_zero_bit(bitmap, resmap->m_bitmap_len,
|
||||||
start)) != -1) {
|
start)) < resmap->m_bitmap_len) {
|
||||||
/* Search reached end of the region */
|
/* Search reached end of the region */
|
||||||
if (offset >= (search_start + search_len))
|
if (offset >= (search_start + search_len))
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1290,10 +1290,8 @@ static int ocfs2_block_group_find_clear_bits(struct ocfs2_super *osb,
|
||||||
found = start = best_offset = best_size = 0;
|
found = start = best_offset = best_size = 0;
|
||||||
bitmap = bg->bg_bitmap;
|
bitmap = bg->bg_bitmap;
|
||||||
|
|
||||||
while((offset = ocfs2_find_next_zero_bit(bitmap, total_bits, start)) != -1) {
|
while ((offset = ocfs2_find_next_zero_bit(bitmap, total_bits, start)) <
|
||||||
if (offset == total_bits)
|
total_bits) {
|
||||||
break;
|
|
||||||
|
|
||||||
if (!ocfs2_test_bg_bit_allocatable(bg_bh, offset)) {
|
if (!ocfs2_test_bg_bit_allocatable(bg_bh, offset)) {
|
||||||
/* We found a zero, but we can't use it as it
|
/* We found a zero, but we can't use it as it
|
||||||
* hasn't been put to disk yet! */
|
* hasn't been put to disk yet! */
|
||||||
|
|
Loading…
Add table
Reference in a new issue