Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Joseph Qi and committed by
Andrew Morton
30dd3478 0bbac3fa

+9 -18
+6 -13
fs/ocfs2/localalloc.c
··· 863 863 864 864 numfound = bitoff = startoff = 0; 865 865 left = le32_to_cpu(alloc->id1.bitmap1.i_total); 866 - while ((bitoff = ocfs2_find_next_zero_bit(bitmap, left, startoff)) != -1) { 867 - if (bitoff == left) { 868 - /* mlog(0, "bitoff (%d) == left", bitoff); */ 869 - break; 870 - } 871 - /* mlog(0, "Found a zero: bitoff = %d, startoff = %d, " 872 - "numfound = %d\n", bitoff, startoff, numfound);*/ 873 - 866 + while ((bitoff = ocfs2_find_next_zero_bit(bitmap, left, startoff)) < 867 + left) { 874 868 /* Ok, we found a zero bit... is it contig. or do we 875 869 * start over?*/ 876 870 if (bitoff == startoff) { ··· 970 976 start = count = 0; 971 977 left = le32_to_cpu(alloc->id1.bitmap1.i_total); 972 978 973 - while ((bit_off = ocfs2_find_next_zero_bit(bitmap, left, start)) 974 - != -1) { 975 - if ((bit_off < left) && (bit_off == start)) { 979 + while ((bit_off = ocfs2_find_next_zero_bit(bitmap, left, start)) < 980 + left) { 981 + if (bit_off == start) { 976 982 count++; 977 983 start++; 978 984 continue; ··· 996 1002 goto bail; 997 1003 } 998 1004 } 999 - if (bit_off >= left) 1000 - break; 1005 + 1001 1006 count = 1; 1002 1007 start = bit_off + 1; 1003 1008 }
+1 -1
fs/ocfs2/reservations.c
··· 414 414 415 415 start = search_start; 416 416 while ((offset = ocfs2_find_next_zero_bit(bitmap, resmap->m_bitmap_len, 417 - start)) != -1) { 417 + start)) < resmap->m_bitmap_len) { 418 418 /* Search reached end of the region */ 419 419 if (offset >= (search_start + search_len)) 420 420 break;
+2 -4
fs/ocfs2/suballoc.c
··· 1290 1290 found = start = best_offset = best_size = 0; 1291 1291 bitmap = bg->bg_bitmap; 1292 1292 1293 - while((offset = ocfs2_find_next_zero_bit(bitmap, total_bits, start)) != -1) { 1294 - if (offset == total_bits) 1295 - break; 1296 - 1293 + while ((offset = ocfs2_find_next_zero_bit(bitmap, total_bits, start)) < 1294 + total_bits) { 1297 1295 if (!ocfs2_test_bg_bit_allocatable(bg_bh, offset)) { 1298 1296 /* We found a zero, but we can't use it as it 1299 1297 * hasn't been put to disk yet! */