Skip to content

Commit 91d743a

Browse files
konisakpm00
authored andcommitted
nilfs2: make superblock data array index computation sparse friendly
Upon running sparse, "warning: dubious: x & !y" is output at an array index calculation within nilfs_load_super_block(). The calculation is not wrong, but to eliminate the sparse warning, replace it with an equivalent calculation. Also, add a comment to make it easier to understand what the unintuitive array index calculation is doing and whether it's correct. Link: https://lkml.kernel.org/r/20240430080019.4242-3-konishi.ryusuke@gmail.com Fixes: e339ad3 ("nilfs2: introduce secondary super block") Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com> Cc: Bart Van Assche <bvanassche@acm.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: kernel test robot <lkp@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent bbf45b7 commit 91d743a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

fs/nilfs2/the_nilfs.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
592592
struct nilfs_super_block **sbp = nilfs->ns_sbp;
593593
struct buffer_head **sbh = nilfs->ns_sbh;
594594
u64 sb2off, devsize = bdev_nr_bytes(nilfs->ns_bdev);
595-
int valid[2], swp = 0;
595+
int valid[2], swp = 0, older;
596596

597597
if (devsize < NILFS_SEG_MIN_BLOCKS * NILFS_MIN_BLOCK_SIZE + 4096) {
598598
nilfs_err(sb, "device size too small");
@@ -648,9 +648,25 @@ static int nilfs_load_super_block(struct the_nilfs *nilfs,
648648
if (swp)
649649
nilfs_swap_super_block(nilfs);
650650

651+
/*
652+
* Calculate the array index of the older superblock data.
653+
* If one has been dropped, set index 0 pointing to the remaining one,
654+
* otherwise set index 1 pointing to the old one (including if both
655+
* are the same).
656+
*
657+
* Divided case valid[0] valid[1] swp -> older
658+
* -------------------------------------------------------------
659+
* Both SBs are invalid 0 0 N/A (Error)
660+
* SB1 is invalid 0 1 1 0
661+
* SB2 is invalid 1 0 0 0
662+
* SB2 is newer 1 1 1 0
663+
* SB2 is older or the same 1 1 0 1
664+
*/
665+
older = valid[1] ^ swp;
666+
651667
nilfs->ns_sbwcount = 0;
652668
nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime);
653-
nilfs->ns_prot_seq = le64_to_cpu(sbp[valid[1] & !swp]->s_last_seq);
669+
nilfs->ns_prot_seq = le64_to_cpu(sbp[older]->s_last_seq);
654670
*sbpp = sbp[0];
655671
return 0;
656672
}

0 commit comments

Comments
 (0)