Commit 98efb4eb authored by David Sterba's avatar David Sterba

btrfs: use helper sizeof_field in struct accessors

There's a helper for obtaining size of a struct member, we can use it
instead of open coding the pointer magic.
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 16c3a476
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#ifndef BTRFS_ACCESSORS_H #ifndef BTRFS_ACCESSORS_H
#define BTRFS_ACCESSORS_H #define BTRFS_ACCESSORS_H
#include <linux/stddef.h>
struct btrfs_map_token { struct btrfs_map_token {
struct extent_buffer *eb; struct extent_buffer *eb;
char *kaddr; char *kaddr;
...@@ -34,13 +36,13 @@ static inline void put_unaligned_le8(u8 val, void *p) ...@@ -34,13 +36,13 @@ static inline void put_unaligned_le8(u8 val, void *p)
read_extent_buffer(eb, (char *)(result), \ read_extent_buffer(eb, (char *)(result), \
((unsigned long)(ptr)) + \ ((unsigned long)(ptr)) + \
offsetof(type, member), \ offsetof(type, member), \
sizeof(((type *)0)->member))) sizeof_field(type, member)))
#define write_eb_member(eb, ptr, type, member, result) (\ #define write_eb_member(eb, ptr, type, member, result) (\
write_extent_buffer(eb, (char *)(result), \ write_extent_buffer(eb, (char *)(result), \
((unsigned long)(ptr)) + \ ((unsigned long)(ptr)) + \
offsetof(type, member), \ offsetof(type, member), \
sizeof(((type *)0)->member))) sizeof_field(type, member)))
#define DECLARE_BTRFS_SETGET_BITS(bits) \ #define DECLARE_BTRFS_SETGET_BITS(bits) \
u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \ u##bits btrfs_get_token_##bits(struct btrfs_map_token *token, \
...@@ -62,25 +64,25 @@ DECLARE_BTRFS_SETGET_BITS(64) ...@@ -62,25 +64,25 @@ DECLARE_BTRFS_SETGET_BITS(64)
static inline u##bits btrfs_##name(const struct extent_buffer *eb, \ static inline u##bits btrfs_##name(const struct extent_buffer *eb, \
const type *s) \ const type *s) \
{ \ { \
static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ static_assert(sizeof(u##bits) == sizeof_field(type, member)); \
return btrfs_get_##bits(eb, s, offsetof(type, member)); \ return btrfs_get_##bits(eb, s, offsetof(type, member)); \
} \ } \
static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \ static inline void btrfs_set_##name(const struct extent_buffer *eb, type *s, \
u##bits val) \ u##bits val) \
{ \ { \
static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ static_assert(sizeof(u##bits) == sizeof_field(type, member)); \
btrfs_set_##bits(eb, s, offsetof(type, member), val); \ btrfs_set_##bits(eb, s, offsetof(type, member), val); \
} \ } \
static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \ static inline u##bits btrfs_token_##name(struct btrfs_map_token *token, \
const type *s) \ const type *s) \
{ \ { \
static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ static_assert(sizeof(u##bits) == sizeof_field(type, member)); \
return btrfs_get_token_##bits(token, s, offsetof(type, member));\ return btrfs_get_token_##bits(token, s, offsetof(type, member));\
} \ } \
static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\ static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\
type *s, u##bits val) \ type *s, u##bits val) \
{ \ { \
static_assert(sizeof(u##bits) == sizeof(((type *)0))->member); \ static_assert(sizeof(u##bits) == sizeof_field(type, member)); \
btrfs_set_token_##bits(token, s, offsetof(type, member), val); \ btrfs_set_token_##bits(token, s, offsetof(type, member), val); \
} }
...@@ -111,17 +113,14 @@ static inline void btrfs_set_##name(type *s, u##bits val) \ ...@@ -111,17 +113,14 @@ static inline void btrfs_set_##name(type *s, u##bits val) \
static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb, static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
struct btrfs_dev_item *s) struct btrfs_dev_item *s)
{ {
static_assert(sizeof(u64) == static_assert(sizeof(u64) == sizeof_field(struct btrfs_dev_item, total_bytes));
sizeof(((struct btrfs_dev_item *)0))->total_bytes); return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes));
return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item,
total_bytes));
} }
static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb, static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb,
struct btrfs_dev_item *s, struct btrfs_dev_item *s,
u64 val) u64 val)
{ {
static_assert(sizeof(u64) == static_assert(sizeof(u64) == sizeof_field(struct btrfs_dev_item, total_bytes));
sizeof(((struct btrfs_dev_item *)0))->total_bytes);
WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize)); WARN_ON(!IS_ALIGNED(val, eb->fs_info->sectorsize));
btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val); btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment