From patchwork Sat Jul 7 01:37:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Landden X-Patchwork-Id: 1168401 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 179873FE4F for ; Sat, 7 Jul 2012 01:38:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751354Ab2GGBhu (ORCPT ); Fri, 6 Jul 2012 21:37:50 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:38321 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751135Ab2GGBht (ORCPT ); Fri, 6 Jul 2012 21:37:49 -0400 Received: by pbbrp8 with SMTP id rp8so15504798pbb.19 for ; Fri, 06 Jul 2012 18:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=HMWjCfIxrw7KpbXu/NPHQQ0wmx0kqP855FTAjUtnyzQ=; b=Vxdxihu/vkZPRzzvr7LUB9iFZyG/YLylb/2SAhp0cGr2B5/M/plqKK3r6AgNc7asAj Zzqx5BHjAJ+RtvaiR81TLDAVtRSMMyFbW12AQO6gpOpigGSTcJQ3OCT5krBMJhsIzTTS qaZsPflQPdCg10e52nlovG/GhL8vzy1gCKgIUVJOBD1Je5yL1sT0KkYTs4fpt2+QgtmF OMsOy3fOS2EHyJp/tBZxsl4zaepALdIRbsQX6SPbw6pUeh7aYsRZ9mxebO/3nA4c6z5V VR8YraDHuuPAfKLsL84G23IGt6iuxq0s1m+Q2db2K3YxvuKc3PxV2m843EOCpS116Yop hdgw== Received: by 10.68.213.7 with SMTP id no7mr22783173pbc.3.1341625068935; Fri, 06 Jul 2012 18:37:48 -0700 (PDT) Received: from shawn-ssd.domain_not_set.invalid (ppp-71-139-6-111.dsl.snfc21.pacbell.net. [71.139.6.111]) by mx.google.com with ESMTPS id gk2sm11486180pbc.8.2012.07.06.18.37.47 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 06 Jul 2012 18:37:48 -0700 (PDT) From: Shawn Landden To: linux-btrfs@vger.kernel.org Cc: Shawn Landen Subject: [PATCH] fix unaligned memory accesses (Closes: #656955) Date: Fri, 6 Jul 2012 18:37:42 -0700 Message-Id: <1341625062-13044-1-git-send-email-shawnlandden@gmail.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Shawn Landen Fix creation of volumes using mkfs.btrfs on armv5. Signed-off-by: Shawn Landen --- 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 + #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;