diff mbox

[14/16] bcache: Make csum_set() implementation easier to read

Message ID 20180315150814.9412-15-bart.vanassche@wdc.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bart Van Assche March 15, 2018, 3:08 p.m. UTC
Introduce two temporary variables to avoid having to repeat
expressions. This patch does not change any functionality.

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
---
 drivers/md/bcache/bcache.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Christoph Hellwig March 15, 2018, 3:57 p.m. UTC | #1
On Thu, Mar 15, 2018 at 08:08:12AM -0700, Bart Van Assche wrote:
> +#define csum_set(i) ({						\
> +	const void *p = (void *)(i) + sizeof(uint64_t);		\
> +	const void *q = bset_bkey_last(i);			\
> +								\
> +	bch_crc64(p, q - p);					\
> +})

Having this as a macro is really ugly.  Any chane to turn this into a
proper function?
diff mbox

Patch

diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 12e5197f186c..72b1ea4576d9 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -777,10 +777,12 @@  static inline bool ptr_available(struct cache_set *c, const struct bkey *k,
  * This is used for various on disk data structures - cache_sb, prio_set, bset,
  * jset: The checksum is _always_ the first 8 bytes of these structs
  */
-#define csum_set(i)							\
-	bch_crc64(((void *) (i)) + sizeof(uint64_t),			\
-		  ((void *) bset_bkey_last(i)) -			\
-		  (((void *) (i)) + sizeof(uint64_t)))
+#define csum_set(i) ({						\
+	const void *p = (void *)(i) + sizeof(uint64_t);		\
+	const void *q = bset_bkey_last(i);			\
+								\
+	bch_crc64(p, q - p);					\
+})
 
 /* Error handling macros */