btrfs-progs: Fix bus error on sparc
authorIvan Jager <aij+@mrph.org>
Fri, 17 Jan 2014 14:00:43 +0000 (15:00 +0100)
committerChris Mason <clm@fb.com>
Fri, 31 Jan 2014 16:22:29 +0000 (08:22 -0800)
commit0511ca4b502f1cbdd5e92c287d97c8356cdaff66
tree0896447a6c31d9bd0a796c5501f59a9781cddc57
parentef3f6124f0b5e8be126999f27f7f299a6bb3fbf6
btrfs-progs: Fix bus error on sparc

Currently, as of 8cae1840afb3ea44dcc298f32983e577480dfee4 when running
btrfs-convert I get a bus error.

The problem is that struct btrfs_key has __attribute__ ((__packed__))
so it is not aligned. Then, a pointer to it's objectid field is taken,
cast to a  void*, then eventually cast back to a u64* and
dereferenced. The problem is that the dereferenced u64* is not
necessarily aligned (ie, not necessarily a valid u64*), resulting in
undefined behavior.

This patch adds a local u64 variable which would of course be properly
aligned and then uses a pointer to that.

I did not modify the call from btrfs_fs_roots_compare_roots as that
uses struct btrfs_root which is a regular struct and would thus have
it's members correctly aligned to begin with.

After patching this I realized Liu Bo had already written a similar
patch, but I think mine is cleaner, so I'm sending it anyway.

Signed-off-by: Ivan Jager <aij+@mrph.org>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
disk-io.c