linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dimitri John Ledkov <xnox@debian.org>
To: linux-btrfs@vger.kernel.org
Cc: Shawn Landen <shawnlandden@gmail.com>,
	Dimitri John Ledkov <xnox@debian.org>
Subject: [PATCH 3/4] Fixing unaligned memory accesses.
Date: Sun, 21 Sep 2014 02:01:21 +0100	[thread overview]
Message-ID: <1411261282-26831-3-git-send-email-xnox@debian.org> (raw)
In-Reply-To: <1411261282-26831-1-git-send-email-xnox@debian.org>

From: Shawn Landen <shawnlandden@gmail.com>

Bug-Debian: http://bugs.debian.org/656955
Signed-off-by: Dimitri John Ledkov <xnox@debian.org>
---
 ctree.h   | 18 ++++++++++++++----
 volumes.c |  5 +++--
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/ctree.h b/ctree.h
index fa73c4a..92c6ad3 100644
--- a/ctree.h
+++ b/ctree.h
@@ -19,6 +19,8 @@
 #ifndef __BTRFS__
 #define __BTRFS__
 
+#include <stdint.h>
+
 #if BTRFS_FLAT_INCLUDES
 #include "list.h"
 #include "kerncompat.h"
@@ -1191,13 +1193,17 @@ struct btrfs_root {
 static inline u##bits btrfs_##name(const struct extent_buffer *eb)	\
 {									\
 	const 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)			\
@@ -1219,11 +1225,15 @@ static inline void btrfs_set_##name(struct extent_buffer *eb,		\
 #define BTRFS_SETGET_STACK_FUNCS(name, type, member, bits)		\
 static inline u##bits btrfs_##name(const 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 388c94e..102380b 100644
--- a/volumes.c
+++ b/volumes.c
@@ -472,10 +472,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;
-- 
2.1.0.rc1


  parent reply	other threads:[~2014-09-21  1:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-21  1:01 [PATCH 1/4] Properly cast to avoid compiler warnings, fixes FTBFS on alpha and ia64 Dimitri John Ledkov
2014-09-21  1:01 ` [PATCH 2/4] Fixes FTBFS with --no-add-needed Dimitri John Ledkov
2014-09-22 12:23   ` David Sterba
2014-09-21  1:01 ` Dimitri John Ledkov [this message]
2014-09-22 13:03   ` [PATCH 3/4] Fixing unaligned memory accesses David Sterba
2014-09-21  1:01 ` [PATCH 4/4] Default to acting like fsck Dimitri John Ledkov
2014-09-21 12:59   ` Tobias Geerinckx-Rice
2014-09-22  8:58     ` Dimitri John Ledkov
2014-09-22 13:13       ` David Sterba

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=1411261282-26831-3-git-send-email-xnox@debian.org \
    --to=xnox@debian.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=shawnlandden@gmail.com \
    /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).