]> git.hungrycats.org Git - linux/commitdiff
btrfs: remove BUG*() from raid56.c
authorQu Wenruo <wqu@suse.com>
Wed, 21 Oct 2026 22:48:47 +0000 (09:18 +1030)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Oct 2026 20:36:18 +0000 (21:36 +0100)
There are several BUG()/BUG_ON() inside raid56.c, which cause
checkpatch warning if code is touching them. This is especially annoying
if using b4, with btrfs-workflow git hooks applied, which makes b4 to
wait for user input but without any output.

Address them by removing one very impossible BUG(), and using ASSERT() for
the remaining ones:

- __remove_rbio_from_cache()
- rbio_is_full()
- unlock_stripe()
  Replace the BUG_ON() with ASSERT().

- finish_parity_scrub()
  Remove the BUG(), as alloc_rbio() has already properly calculated
  real_stripes and nr_data using the number of parity.

  Furthermore, initialize @has_qstripe at the beginning of the function
  using the bioc->map_type directly.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/raid56.c

index 080be467c6fcb9d2fa57f64c2a92d500c232ef49..59aad807f98ab5b85403d253640cebd1255cd7a9 100644 (file)
@@ -510,7 +510,7 @@ static void __remove_rbio_from_cache(struct btrfs_raid_bio *rbio)
                        if (!list_empty(&rbio->hash_list)) {
                                list_del_init(&rbio->hash_list);
                                refcount_dec(&rbio->refs);
-                               BUG_ON(!list_empty(&rbio->plug_list));
+                               ASSERT(list_empty(&rbio->plug_list));
                        }
                }
        }
@@ -634,7 +634,7 @@ static int rbio_is_full(struct btrfs_raid_bio *rbio)
        spin_lock(&rbio->bio_list_lock);
        if (size != rbio->nr_data * stripe_len)
                ret = 0;
-       BUG_ON(size > rbio->nr_data * stripe_len);
+       ASSERT(size <= rbio->nr_data * stripe_len);
        spin_unlock(&rbio->bio_list_lock);
 
        return ret;
@@ -881,7 +881,7 @@ static noinline void unlock_stripe(struct btrfs_raid_bio *rbio)
                    test_bit(RBIO_CACHE_BIT, &rbio->flags)) {
                        keep_cache = true;
                        clear_bit(RBIO_RMW_LOCKED_BIT, &rbio->flags);
-                       BUG_ON(!bio_list_empty(&rbio->bio_list));
+                       ASSERT(bio_list_empty(&rbio->bio_list));
                        goto done;
                }
 
@@ -2719,7 +2719,7 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
        unsigned long *pbitmap = &rbio->finish_pbitmap;
        int nr_data = rbio->nr_data;
        int sectornr;
-       bool has_qstripe;
+       const bool has_qstripe = rbio->bioc->map_type & BTRFS_BLOCK_GROUP_RAID6;
        struct page *page;
        phys_addr_t p_paddr = INVALID_PADDR;
        phys_addr_t q_paddr = INVALID_PADDR;
@@ -2729,13 +2729,6 @@ static int finish_parity_scrub(struct btrfs_raid_bio *rbio)
 
        bio_list_init(&bio_list);
 
-       if (rbio->real_stripes - rbio->nr_data == 1)
-               has_qstripe = false;
-       else if (rbio->real_stripes - rbio->nr_data == 2)
-               has_qstripe = true;
-       else
-               BUG();
-
        /*
         * Replace is running and our P/Q stripe is being replaced, then we
         * need to duplicate the final write to replace target.