Skip to content

Commit a5fda11

Browse files
committed
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 <[email protected]>
1 parent bd2c38c commit a5fda11

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

fs/ext4/ext4_extents.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,11 @@ struct partial_cluster {
173173
#define EXT_MAX_EXTENT(__hdr__) \
174174
((le16_to_cpu((__hdr__)->eh_max)) ? \
175175
((EXT_FIRST_EXTENT((__hdr__)) + le16_to_cpu((__hdr__)->eh_max) - 1)) \
176-
: 0)
176+
: NULL)
177177
#define EXT_MAX_INDEX(__hdr__) \
178178
((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)
180181

181182
static inline struct ext4_extent_header *ext_inode_hdr(struct inode *inode)
182183
{

fs/ext4/mballoc.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,6 +2478,12 @@ static bool ext4_mb_good_group(struct ext4_allocation_context *ac,
24782478
* This could return negative error code if something goes wrong
24792479
* during ext4_mb_init_group(). This should not be called with
24802480
* 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"!
24812487
*/
24822488
static int ext4_mb_good_group_nolock(struct ext4_allocation_context *ac,
24832489
ext4_group_t group, int cr)
@@ -2491,17 +2497,21 @@ static int ext4_mb_good_group_nolock(struct ext4_allocation_context *ac,
24912497

24922498
if (sbi->s_mb_stats)
24932499
atomic64_inc(&sbi->s_bal_cX_groups_considered[ac->ac_criteria]);
2494-
if (should_lock)
2500+
if (should_lock) {
24952501
ext4_lock_group(sb, group);
2502+
__release(ext4_group_lock_ptr(sb, group));
2503+
}
24962504
free = grp->bb_free;
24972505
if (free == 0)
24982506
goto out;
24992507
if (cr <= 2 && free < ac->ac_g_ex.fe_len)
25002508
goto out;
25012509
if (unlikely(EXT4_MB_GRP_BBITMAP_CORRUPT(grp)))
25022510
goto out;
2503-
if (should_lock)
2511+
if (should_lock) {
2512+
__acquire(ext4_group_lock_ptr(sb, group));
25042513
ext4_unlock_group(sb, group);
2514+
}
25052515

25062516
/* We only do this if the grp has never been initialized */
25072517
if (unlikely(EXT4_MB_GRP_NEED_INIT(grp))) {
@@ -2528,12 +2538,16 @@ static int ext4_mb_good_group_nolock(struct ext4_allocation_context *ac,
25282538
return ret;
25292539
}
25302540

2531-
if (should_lock)
2541+
if (should_lock) {
25322542
ext4_lock_group(sb, group);
2543+
__release(ext4_group_lock_ptr(sb, group));
2544+
}
25332545
ret = ext4_mb_good_group(ac, group, cr);
25342546
out:
2535-
if (should_lock)
2547+
if (should_lock) {
2548+
__acquire(ext4_group_lock_ptr(sb, group));
25362549
ext4_unlock_group(sb, group);
2550+
}
25372551
return ret;
25382552
}
25392553

@@ -2969,6 +2983,7 @@ int ext4_seq_mb_stats_show(struct seq_file *seq, void *offset)
29692983
}
29702984

29712985
static void *ext4_mb_seq_structs_summary_start(struct seq_file *seq, loff_t *pos)
2986+
__acquires(&EXT4_SB(sb)->s_mb_rb_lock)
29722987
{
29732988
struct super_block *sb = PDE_DATA(file_inode(seq->file));
29742989
unsigned long position;
@@ -3041,6 +3056,7 @@ static int ext4_mb_seq_structs_summary_show(struct seq_file *seq, void *v)
30413056
}
30423057

30433058
static void ext4_mb_seq_structs_summary_stop(struct seq_file *seq, void *v)
3059+
__releases(&EXT4_SB(sb)->s_mb_rb_lock)
30443060
{
30453061
struct super_block *sb = PDE_DATA(file_inode(seq->file));
30463062

@@ -6275,6 +6291,8 @@ __acquires(bitlock)
62756291
static int ext4_try_to_trim_range(struct super_block *sb,
62766292
struct ext4_buddy *e4b, ext4_grpblk_t start,
62776293
ext4_grpblk_t max, ext4_grpblk_t minblocks)
6294+
__acquires(ext4_group_lock_ptr(sb, e4b->bd_group))
6295+
__releases(ext4_group_lock_ptr(sb, e4b->bd_group))
62786296
{
62796297
ext4_grpblk_t next, count, free_count;
62806298
void *bitmap;

0 commit comments

Comments
 (0)