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

ext4: fix sparse warnings

Add sparse annotations to suppress false positive context imbalance
warnings, and use NULL instead of 0 in EXT_MAX_{EXTENT,INDEX}.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>

+25 -6
+3 -2
fs/ext4/ext4_extents.h
··· 173 173 #define EXT_MAX_EXTENT(__hdr__) \ 174 174 ((le16_to_cpu((__hdr__)->eh_max)) ? \ 175 175 ((EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)) \ 176 - : 0) 176 + : NULL) 177 177 #define EXT_MAX_INDEX(__hdr__) \ 178 178 ((le16_to_cpu((__hdr__)->eh_max)) ? \ 179 - ((EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)) : 0) 179 + ((EXT_FIRST_INDEX((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)) \ 180 + : NULL) 180 181 181 182 static inline struct ext4_extent_header *ext_inode_hdr(struct inode *inode) 182 183 {
+22 -4
fs/ext4/mballoc.c
··· 2478 2478 * This could return negative error code if something goes wrong 2479 2479 * during ext4_mb_init_group(). This should not be called with 2480 2480 * ext4_lock_group() held. 2481 + * 2482 + * Note: because we are conditionally operating with the group lock in 2483 + * the EXT4_MB_STRICT_CHECK case, we need to fake out sparse in this 2484 + * function using __acquire and __release. This means we need to be 2485 + * super careful before messing with the error path handling via "goto 2486 + * out"! 2481 2487 */ 2482 2488 static int ext4_mb_good_group_nolock(struct ext4_allocation_context *ac, 2483 2489 ext4_group_t group, int cr) ··· 2497 2491 2498 2492 if (sbi->s_mb_stats) 2499 2493 atomic64_inc(&sbi->s_bal_cX_groups_considered[ac->ac_criteria]); 2500 - if (should_lock) 2494 + if (should_lock) { 2501 2495 ext4_lock_group(sb, group); 2496 + __release(ext4_group_lock_ptr(sb, group)); 2497 + } 2502 2498 free = grp->bb_free; 2503 2499 if (free == 0) 2504 2500 goto out; ··· 2508 2500 goto out; 2509 2501 if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(grp))) 2510 2502 goto out; 2511 - if (should_lock) 2503 + if (should_lock) { 2504 + __acquire(ext4_group_lock_ptr(sb, group)); 2512 2505 ext4_unlock_group(sb, group); 2506 + } 2513 2507 2514 2508 /* We only do this if the grp has never been initialized */ 2515 2509 if (unlikely(EXT4_MB_GRP_NEED_INIT(grp))) { ··· 2538 2528 return ret; 2539 2529 } 2540 2530 2541 - if (should_lock) 2531 + if (should_lock) { 2542 2532 ext4_lock_group(sb, group); 2533 + __release(ext4_group_lock_ptr(sb, group)); 2534 + } 2543 2535 ret = ext4_mb_good_group(ac, group, cr); 2544 2536 out: 2545 - if (should_lock) 2537 + if (should_lock) { 2538 + __acquire(ext4_group_lock_ptr(sb, group)); 2546 2539 ext4_unlock_group(sb, group); 2540 + } 2547 2541 return ret; 2548 2542 } 2549 2543 ··· 2983 2969 } 2984 2970 2985 2971 static void *ext4_mb_seq_structs_summary_start(struct seq_file *seq, loff_t *pos) 2972 + __acquires(&EXT4_SB(sb)->s_mb_rb_lock) 2986 2973 { 2987 2974 struct super_block *sb = PDE_DATA(file_inode(seq->file)); 2988 2975 unsigned long position; ··· 3056 3041 } 3057 3042 3058 3043 static void ext4_mb_seq_structs_summary_stop(struct seq_file *seq, void *v) 3044 + __releases(&EXT4_SB(sb)->s_mb_rb_lock) 3059 3045 { 3060 3046 struct super_block *sb = PDE_DATA(file_inode(seq->file)); 3061 3047 ··· 6291 6275 static int ext4_try_to_trim_range(struct super_block *sb, 6292 6276 struct ext4_buddy *e4b, ext4_grpblk_t start, 6293 6277 ext4_grpblk_t max, ext4_grpblk_t minblocks) 6278 + __acquires(ext4_group_lock_ptr(sb, e4b->bd_group)) 6279 + __releases(ext4_group_lock_ptr(sb, e4b->bd_group)) 6294 6280 { 6295 6281 ext4_grpblk_t next, count, free_count; 6296 6282 void *bitmap;