]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: constify and cleanup variables in comparators
authorDavid Sterba <dsterba@suse.com>
Mon, 26 Jul 2021 12:15:26 +0000 (14:15 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 23 Aug 2021 11:19:03 +0000 (13:19 +0200)
Comparators just read the data and thus get const parameters. This
should be also preserved by the local variables, update all comparators
passed to sort or bsearch.

Cleanups:

- unnecessary casts are dropped
- btrfs_cmp_device_free_bytes is cleaned up to follow the common pattern
  and 'inline' is dropped as the function address is taken

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/raid56.c
fs/btrfs/send.c
fs/btrfs/super.c
fs/btrfs/tree-log.c
fs/btrfs/volumes.c

index a40a45a007d456a4944a3498fbefa154870570a0..d8d268ca8aa76ed85ecf046dbbb1af9efbbf99eb 100644 (file)
@@ -1636,10 +1636,10 @@ struct btrfs_plug_cb {
 static int plug_cmp(void *priv, const struct list_head *a,
                    const struct list_head *b)
 {
-       struct btrfs_raid_bio *ra = container_of(a, struct btrfs_raid_bio,
-                                                plug_list);
-       struct btrfs_raid_bio *rb = container_of(b, struct btrfs_raid_bio,
-                                                plug_list);
+       const struct btrfs_raid_bio *ra = container_of(a, struct btrfs_raid_bio,
+                                                      plug_list);
+       const struct btrfs_raid_bio *rb = container_of(b, struct btrfs_raid_bio,
+                                                      plug_list);
        u64 a_sector = ra->bio_list.head->bi_iter.bi_sector;
        u64 b_sector = rb->bio_list.head->bi_iter.bi_sector;
 
index 6ac37ae6c8117a37581c1a230704e6e7de758581..75cff564dedfbf31b22b6c800694296c05b9cde9 100644 (file)
@@ -1198,7 +1198,7 @@ struct backref_ctx {
 static int __clone_root_cmp_bsearch(const void *key, const void *elt)
 {
        u64 root = (u64)(uintptr_t)key;
-       struct clone_root *cr = (struct clone_root *)elt;
+       const struct clone_root *cr = elt;
 
        if (root < cr->root->root_key.objectid)
                return -1;
@@ -1209,8 +1209,8 @@ static int __clone_root_cmp_bsearch(const void *key, const void *elt)
 
 static int __clone_root_cmp_sort(const void *e1, const void *e2)
 {
-       struct clone_root *cr1 = (struct clone_root *)e1;
-       struct clone_root *cr2 = (struct clone_root *)e2;
+       const struct clone_root *cr1 = e1;
+       const struct clone_root *cr2 = e2;
 
        if (cr1->root->root_key.objectid < cr2->root->root_key.objectid)
                return -1;
index d07b18b2b250553c518727a3f2dc2581c55633dd..35ff142ad242c9ad84ceee2bd1599206aef56f27 100644 (file)
@@ -2096,16 +2096,15 @@ restore:
 }
 
 /* Used to sort the devices by max_avail(descending sort) */
-static inline int btrfs_cmp_device_free_bytes(const void *dev_info1,
-                                      const void *dev_info2)
+static int btrfs_cmp_device_free_bytes(const void *a, const void *b)
 {
-       if (((struct btrfs_device_info *)dev_info1)->max_avail >
-           ((struct btrfs_device_info *)dev_info2)->max_avail)
+       const struct btrfs_device_info *dev_info1 = a;
+       const struct btrfs_device_info *dev_info2 = b;
+
+       if (dev_info1->max_avail > dev_info2->max_avail)
                return -1;
-       else if (((struct btrfs_device_info *)dev_info1)->max_avail <
-                ((struct btrfs_device_info *)dev_info2)->max_avail)
+       else if (dev_info1->max_avail < dev_info2->max_avail)
                return 1;
-       else
        return 0;
 }
 
index 8dde5c08a48f3cb9abb17f3960ad798bb5497b50..191dea1d24166776c5c1deb22b95aa3657bab176 100644 (file)
@@ -4191,7 +4191,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
 static int extent_cmp(void *priv, const struct list_head *a,
                      const struct list_head *b)
 {
-       struct extent_map *em1, *em2;
+       const struct extent_map *em1, *em2;
 
        em1 = list_entry(a, struct extent_map, list);
        em2 = list_entry(b, struct extent_map, list);
index c7339f163bda5eae4f7f29542d5ce679f22de198..d42fb61aadc359beebc4d8ca81b997655bdd09f3 100644 (file)
@@ -1216,7 +1216,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
 static int devid_cmp(void *priv, const struct list_head *a,
                     const struct list_head *b)
 {
-       struct btrfs_device *dev1, *dev2;
+       const struct btrfs_device *dev1, *dev2;
 
        dev1 = list_entry(a, struct btrfs_device, dev_list);
        dev2 = list_entry(b, struct btrfs_device, dev_list);