Skip to content

Commit 1a0ac8b

Browse files
committed
erofs: fix erofs_insert_workgroup() lockref usage
As Linus pointed out [1], lockref_put_return() is fundamentally designed to be something that can fail. It behaves as a fastpath-only thing, and the failure case needs to be handled anyway. Actually, since the new pcluster was just allocated without being populated, it won't be accessed by others until it is inserted into XArray, so lockref helpers are actually unneeded here. Let's just set the proper reference count on initializing. [1] https://lore.kernel.org/r/CAHk-=whCga8BeQnJ3ZBh_Hfm9ctba_wpF444LpwRybVNMzO6Dw@mail.gmail.com Fixes: 7674a42 ("erofs: use struct lockref to replace handcrafted approach") Reviewed-by: Chao Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent f5deddc commit 1a0ac8b

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

fs/erofs/utils.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
7777
struct erofs_sb_info *const sbi = EROFS_SB(sb);
7878
struct erofs_workgroup *pre;
7979

80-
/*
81-
* Bump up before making this visible to others for the XArray in order
82-
* to avoid potential UAF without serialized by xa_lock.
83-
*/
84-
lockref_get(&grp->lockref);
85-
80+
DBG_BUGON(grp->lockref.count < 1);
8681
repeat:
8782
xa_lock(&sbi->managed_pslots);
8883
pre = __xa_cmpxchg(&sbi->managed_pslots, grp->index,
@@ -96,7 +91,6 @@ struct erofs_workgroup *erofs_insert_workgroup(struct super_block *sb,
9691
cond_resched();
9792
goto repeat;
9893
}
99-
lockref_put_return(&grp->lockref);
10094
grp = pre;
10195
}
10296
xa_unlock(&sbi->managed_pslots);

fs/erofs/zdata.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
796796
return PTR_ERR(pcl);
797797

798798
spin_lock_init(&pcl->obj.lockref.lock);
799+
pcl->obj.lockref.count = 1; /* one ref for this request */
799800
pcl->algorithmformat = map->m_algorithmformat;
800801
pcl->length = 0;
801802
pcl->partial = true;

0 commit comments

Comments
 (0)