]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: Early return to avoid unnecessary lock
authorAlan Huang <mmpgouride@gmail.com>
Mon, 12 May 2025 18:44:26 +0000 (02:44 +0800)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:59 +0000 (20:14 -0400)
Signed-off-by: Alan Huang <mmpgouride@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c

index 51dfd2f24c209713a5a5183a7d0649023b97fed8..daf23d471d4f1ceebe1f6fb32f5a89d567080e9e 100644 (file)
@@ -2576,19 +2576,18 @@ u64 bch2_min_rw_member_capacity(struct bch_fs *c)
 static bool bch2_dev_has_open_write_point(struct bch_fs *c, struct bch_dev *ca)
 {
        struct open_bucket *ob;
-       bool ret = false;
 
        for (ob = c->open_buckets;
             ob < c->open_buckets + ARRAY_SIZE(c->open_buckets);
             ob++) {
-               spin_lock(&ob->lock);
-               if (ob->valid && !ob->on_partial_list &&
-                   ob->dev == ca->dev_idx)
-                       ret = true;
-               spin_unlock(&ob->lock);
+               scoped_guard(spinlock, &ob->lock) {
+                       if (ob->valid && !ob->on_partial_list &&
+                           ob->dev == ca->dev_idx)
+                               return true;
+               }
        }
 
-       return ret;
+       return false;
 }
 
 void bch2_dev_allocator_set_rw(struct bch_fs *c, struct bch_dev *ca, bool rw)