From: Shawn Landden <shawnlandden@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Shawn Landen <shawnlandden@gmail.com>
Subject: [PATCH] fix unaligned memory accesses (Closes: #656955)
Date: Fri, 6 Jul 2012 18:37:42 -0700 [thread overview]
Message-ID: <1341625062-13044-1-git-send-email-shawnlandden@gmail.com> (raw)
From: Shawn Landen <shawnlandden@gmail.com>
Fix creation of volumes using mkfs.btrfs on armv5.
Signed-off-by: Shawn Landen <shawnlandden@gmail.com>
---
ctree.h | 26 ++++++++++++++++++++------
volumes.c | 5 +++--
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/ctree.h b/ctree.h
index 6545c50..ef3f0cc 100644
--- a/ctree.h
+++ b/ctree.h
@@ -19,6 +19,8 @@
#ifndef __BTRFS__
#define __BTRFS__
+#include <stdint.h>
+
#include "list.h"
#include "kerncompat.h"
#include "radix-tree.h"
@@ -970,13 +972,17 @@ struct btrfs_root {
static inline u##bits btrfs_##name(struct extent_buffer *eb) \
{ \
struct btrfs_header *h = (struct btrfs_header *)eb->data; \
- return le##bits##_to_cpu(h->member); \
+ uint##bits##_t t; \
+ memcpy(&t, &h->member, sizeof(h->member)); \
+ return le##bits##_to_cpu(t); \
} \
static inline void btrfs_set_##name(struct extent_buffer *eb, \
u##bits val) \
{ \
struct btrfs_header *h = (struct btrfs_header *)eb->data; \
- h->member = cpu_to_le##bits(val); \
+ uint##bits##_t t; \
+ t = cpu_to_le##bits(val); \
+ memcpy(&h->member, &t, sizeof(h->member)); \
}
#define BTRFS_SETGET_FUNCS(name, type, member, bits) \
@@ -984,25 +990,33 @@ static inline u##bits btrfs_##name(struct extent_buffer *eb, \
type *s) \
{ \
unsigned long offset = (unsigned long)s; \
+ uint##bits##_t t; \
type *p = (type *) (eb->data + offset); \
- return le##bits##_to_cpu(p->member); \
+ memcpy(&t, &p->member, sizeof(p->member)); \
+ return le##bits##_to_cpu(t); \
} \
static inline void btrfs_set_##name(struct extent_buffer *eb, \
type *s, u##bits val) \
{ \
unsigned long offset = (unsigned long)s; \
+ uint##bits##_t t; \
type *p = (type *) (eb->data + offset); \
- p->member = cpu_to_le##bits(val); \
+ t = cpu_to_le##bits(val); \
+ memcpy(&p->member, &t, sizeof(p->member)); \
}
#define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits) \
static inline u##bits btrfs_##name(type *s) \
{ \
- return le##bits##_to_cpu(s->member); \
+ uint##bits##_t t; \
+ memcpy(&t, &s->member, sizeof(s->member)); \
+ return le##bits##_to_cpu(t); \
} \
static inline void btrfs_set_##name(type *s, u##bits val) \
{ \
- s->member = cpu_to_le##bits(val); \
+ uint##bits##_t t; \
+ t = cpu_to_le##bits(val); \
+ memcpy(&s->member, &t, sizeof(s->member)); \
}
BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
diff --git a/volumes.c b/volumes.c
index 8dca5e1..0401eeb 100644
--- a/volumes.c
+++ b/volumes.c
@@ -425,10 +425,11 @@ static int find_next_chunk(struct btrfs_root *root, u64 objectid, u64 *offset)
if (found_key.objectid != objectid)
*offset = 0;
else {
+ u64 t;
chunk = btrfs_item_ptr(path->nodes[0], path->slots[0],
struct btrfs_chunk);
- *offset = found_key.offset +
- btrfs_chunk_length(path->nodes[0], chunk);
+ t = found_key.offset + btrfs_chunk_length(path->nodes[0], chunk);
+ memcpy(offset, &t, sizeof(found_key.offset));
}
}
ret = 0;
--
1.7.10.4
next reply other threads:[~2012-07-07 1:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-07 1:37 Shawn Landden [this message]
2012-07-07 10:48 ` [PATCH] fix unaligned memory accesses (Closes: #656955) Alexander Block
2012-07-09 18:16 ` Chris Mason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1341625062-13044-1-git-send-email-shawnlandden@gmail.com \
--to=shawnlandden@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).