Commit e97659ce authored by David Sterba's avatar David Sterba

btrfs: use unaligned helpers for stack and header set/get helpers

In the definitions generated by BTRFS_SETGET_HEADER_FUNCS there's direct
pointer assignment but we should use the helpers for unaligned access
for clarity. It hasn't been a problem so far because of the natural
alignment.

Similarly for BTRFS_SETGET_STACK_FUNCS, that usually get a structure
from stack that has an aligned start but some members may not be aligned
due to packing. This as well hasn't caused problems so far.

Move the put/get_unaligned_le8 stubs to ctree.h so we can use them.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 6994ca36
...@@ -1420,6 +1420,16 @@ static inline void btrfs_init_map_token(struct btrfs_map_token *token, ...@@ -1420,6 +1420,16 @@ static inline void btrfs_init_map_token(struct btrfs_map_token *token,
#define cpu_to_le8(v) (v) #define cpu_to_le8(v) (v)
#define __le8 u8 #define __le8 u8
static inline u8 get_unaligned_le8(const void *p)
{
return *(u8 *)p;
}
static inline void put_unaligned_le8(u8 val, void *p)
{
*(u8 *)p = val;
}
#define read_eb_member(eb, ptr, type, member, result) (\ #define read_eb_member(eb, ptr, type, member, result) (\
read_extent_buffer(eb, (char *)(result), \ read_extent_buffer(eb, (char *)(result), \
((unsigned long)(ptr)) + \ ((unsigned long)(ptr)) + \
...@@ -1478,27 +1488,25 @@ static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\ ...@@ -1478,27 +1488,25 @@ static inline void btrfs_set_token_##name(struct btrfs_map_token *token,\
static inline u##bits btrfs_##name(const struct extent_buffer *eb) \ static inline u##bits btrfs_##name(const struct extent_buffer *eb) \
{ \ { \
const type *p = page_address(eb->pages[0]); \ const type *p = page_address(eb->pages[0]); \
u##bits res = le##bits##_to_cpu(p->member); \ return get_unaligned_le##bits(&p->member); \
return res; \
} \ } \
static inline void btrfs_set_##name(const struct extent_buffer *eb, \ static inline void btrfs_set_##name(const struct extent_buffer *eb, \
u##bits val) \ u##bits val) \
{ \ { \
type *p = page_address(eb->pages[0]); \ type *p = page_address(eb->pages[0]); \
p->member = cpu_to_le##bits(val); \ put_unaligned_le##bits(val, &p->member); \
} }
#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \ #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
static inline u##bits btrfs_##name(const type *s) \ static inline u##bits btrfs_##name(const type *s) \
{ \ { \
return le##bits##_to_cpu(s->member); \ return get_unaligned_le##bits(&s->member); \
} \ } \
static inline void btrfs_set_##name(type *s, u##bits val) \ static inline void btrfs_set_##name(type *s, u##bits val) \
{ \ { \
s->member = cpu_to_le##bits(val); \ put_unaligned_le##bits(val, &s->member); \
} }
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)
{ {
......
...@@ -7,16 +7,6 @@ ...@@ -7,16 +7,6 @@
#include "ctree.h" #include "ctree.h"
static inline u8 get_unaligned_le8(const void *p)
{
return *(u8 *)p;
}
static inline void put_unaligned_le8(u8 val, void *p)
{
*(u8 *)p = val;
}
static bool check_setget_bounds(const struct extent_buffer *eb, static bool check_setget_bounds(const struct extent_buffer *eb,
const void *ptr, unsigned off, int size) const void *ptr, unsigned off, int size)
{ {
......
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