diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-04-12 04:54:12 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:20 -0400 |
commit | 3ea2b1e12898154d6fae49b22a3509521ba49d38 (patch) | |
tree | a7761fcbec401fbf3a8593a5a3c9a58f09f60322 | |
parent | a0e0bda117d80b107c137e4c6cd0fb9814bd5214 (diff) | |
download | linux-stable-3ea2b1e12898154d6fae49b22a3509521ba49d38.tar.gz linux-stable-3ea2b1e12898154d6fae49b22a3509521ba49d38.tar.bz2 linux-stable-3ea2b1e12898154d6fae49b22a3509521ba49d38.zip |
bcachefs: cmp_int()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r-- | fs/bcachefs/alloc_background.c | 8 | ||||
-rw-r--r-- | fs/bcachefs/bkey.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/bkey.h | 4 | ||||
-rw-r--r-- | fs/bcachefs/bset.h | 2 | ||||
-rw-r--r-- | fs/bcachefs/btree_update_leaf.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/ec.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/fs.h | 2 | ||||
-rw-r--r-- | fs/bcachefs/journal_seq_blacklist.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/movinggc.c | 4 | ||||
-rw-r--r-- | fs/bcachefs/replicas.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/sysfs.c | 6 | ||||
-rw-r--r-- | fs/bcachefs/util.h | 2 |
12 files changed, 20 insertions, 18 deletions
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c index acd7be90fc47..b3a8ff0b1daa 100644 --- a/fs/bcachefs/alloc_background.c +++ b/fs/bcachefs/alloc_background.c @@ -687,16 +687,16 @@ static inline int bucket_alloc_cmp(alloc_heap *h, struct alloc_heap_entry l, struct alloc_heap_entry r) { - return (l.key > r.key) - (l.key < r.key) ?: - (l.nr < r.nr) - (l.nr > r.nr) ?: - (l.bucket > r.bucket) - (l.bucket < r.bucket); + return cmp_int(l.key, r.key) ?: + cmp_int(r.nr, l.nr) ?: + cmp_int(l.bucket, r.bucket); } static inline int bucket_idx_cmp(const void *_l, const void *_r) { const struct alloc_heap_entry *l = _l, *r = _r; - return (l->bucket > r->bucket) - (l->bucket < r->bucket); + return cmp_int(l->bucket, r->bucket); } static void find_reclaimable_buckets_lru(struct bch_fs *c, struct bch_dev *ca) diff --git a/fs/bcachefs/bkey.c b/fs/bcachefs/bkey.c index 8a3295ff9631..8b3c9ae8d266 100644 --- a/fs/bcachefs/bkey.c +++ b/fs/bcachefs/bkey.c @@ -1024,7 +1024,7 @@ static inline int __bkey_cmp_bits(const u64 *l, const u64 *r, r_v = *r; } - return (l_v > r_v) - (l_v < r_v); + return cmp_int(l_v, r_v); } #endif diff --git a/fs/bcachefs/bkey.h b/fs/bcachefs/bkey.h index 44044fcd6f9f..45de61d492a4 100644 --- a/fs/bcachefs/bkey.h +++ b/fs/bcachefs/bkey.h @@ -217,8 +217,8 @@ void bch2_bkey_swab_key(const struct bkey_format *, struct bkey_packed *); static __always_inline int bversion_cmp(struct bversion l, struct bversion r) { - return (l.hi > r.hi) - (l.hi < r.hi) ?: - (l.lo > r.lo) - (l.lo < r.lo); + return cmp_int(l.hi, r.hi) ?: + cmp_int(l.lo, r.lo); } #define ZERO_VERSION ((struct bversion) { .hi = 0, .lo = 0 }) diff --git a/fs/bcachefs/bset.h b/fs/bcachefs/bset.h index 329ffb0b6b3d..da3e41cc9757 100644 --- a/fs/bcachefs/bset.h +++ b/fs/bcachefs/bset.h @@ -465,7 +465,7 @@ static inline int bkey_iter_cmp(struct btree *b, { return bkey_cmp_packed(b, l, r) ?: (int) bkey_deleted(r) - (int) bkey_deleted(l) - ?: (l > r) - (l < r); + ?: cmp_int(l, r); } static inline int btree_node_iter_cmp(struct btree *b, diff --git a/fs/bcachefs/btree_update_leaf.c b/fs/bcachefs/btree_update_leaf.c index 8e686dc42f9d..48d3be517471 100644 --- a/fs/bcachefs/btree_update_leaf.c +++ b/fs/bcachefs/btree_update_leaf.c @@ -55,7 +55,7 @@ static void btree_trans_unlock_write(struct btree_trans *trans) static inline int btree_trans_cmp(struct btree_insert_entry l, struct btree_insert_entry r) { - return (l.deferred > r.deferred) - (l.deferred < r.deferred) ?: + return cmp_int(l.deferred, r.deferred) ?: btree_iter_cmp(l.iter, r.iter); } diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c index ea009f0ff829..6a357e5b652e 100644 --- a/fs/bcachefs/ec.c +++ b/fs/bcachefs/ec.c @@ -951,7 +951,7 @@ static int unsigned_cmp(const void *_l, const void *_r) unsigned l = *((const unsigned *) _l); unsigned r = *((const unsigned *) _r); - return (l > r) - (l < r); + return cmp_int(l, r); } /* pick most common bucket size: */ diff --git a/fs/bcachefs/fs.h b/fs/bcachefs/fs.h index b9a8a9bc3e90..e72d6a58b322 100644 --- a/fs/bcachefs/fs.h +++ b/fs/bcachefs/fs.h @@ -54,7 +54,7 @@ struct bch_inode_info { static inline int ptrcmp(void *l, void *r) { - return (l > r) - (l < r); + return cmp_int(l, r); } #define __bch2_lock_inodes(_lock, ...) \ diff --git a/fs/bcachefs/journal_seq_blacklist.c b/fs/bcachefs/journal_seq_blacklist.c index 0df8dfccd5b5..ae64bf3248ef 100644 --- a/fs/bcachefs/journal_seq_blacklist.c +++ b/fs/bcachefs/journal_seq_blacklist.c @@ -136,7 +136,7 @@ static int journal_seq_blacklist_table_cmp(const void *_l, const struct journal_seq_blacklist_table_entry *l = _l; const struct journal_seq_blacklist_table_entry *r = _r; - return (l->start > r->start) - (l->start < r->start); + return cmp_int(l->start, r->start); } bool bch2_journal_seq_is_blacklisted(struct bch_fs *c, u64 seq, diff --git a/fs/bcachefs/movinggc.c b/fs/bcachefs/movinggc.c index 78d9ca8bfc5e..aba13e6ea4ff 100644 --- a/fs/bcachefs/movinggc.c +++ b/fs/bcachefs/movinggc.c @@ -54,7 +54,7 @@ static inline int sectors_used_cmp(copygc_heap *heap, struct copygc_heap_entry l, struct copygc_heap_entry r) { - return (l.sectors > r.sectors) - (l.sectors < r.sectors); + return cmp_int(l.sectors, r.sectors); } static int bucket_offset_cmp(const void *_l, const void *_r, size_t size) @@ -62,7 +62,7 @@ static int bucket_offset_cmp(const void *_l, const void *_r, size_t size) const struct copygc_heap_entry *l = _l; const struct copygc_heap_entry *r = _r; - return (l->offset > r->offset) - (l->offset < r->offset); + return cmp_int(l->offset, r->offset); } static bool __copygc_pred(struct bch_dev *ca, diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c index b66217989b71..b1df2c1ce4a4 100644 --- a/fs/bcachefs/replicas.c +++ b/fs/bcachefs/replicas.c @@ -12,7 +12,7 @@ static int bch2_cpu_replicas_to_sb_replicas(struct bch_fs *, static inline int u8_cmp(u8 l, u8 r) { - return (l > r) - (l < r); + return cmp_int(l, r); } static void verify_replicas_entry_sorted(struct bch_replicas_entry *e) diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c index db87a63b97cc..f4b70f66d0ac 100644 --- a/fs/bcachefs/sysfs.c +++ b/fs/bcachefs/sysfs.c @@ -751,10 +751,10 @@ static unsigned bucket_oldest_gen_fn(struct bch_fs *c, struct bch_dev *ca, static int unsigned_cmp(const void *_l, const void *_r) { - unsigned l = *((unsigned *) _l); - unsigned r = *((unsigned *) _r); + const unsigned *l = _l; + const unsigned *r = _r; - return (l > r) - (l < r); + return cmp_int(*l, *r); } static ssize_t show_quantiles(struct bch_fs *c, struct bch_dev *ca, diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index dc40a52ac8c7..59c8a1dac7be 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -743,4 +743,6 @@ static inline void acc_u64s_percpu(u64 *acc, const u64 __percpu *src, u64 *bch2_acc_percpu_u64s(u64 __percpu *, unsigned); +#define cmp_int(l, r) ((l > r) - (l < r)) + #endif /* _BCACHEFS_UTIL_H */ |