From patchwork Sun Sep 21 01:01:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dimitri John Ledkov X-Patchwork-Id: 4942911 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 26DB2BEEA5 for ; Sun, 21 Sep 2014 01:01:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4C0522016C for ; Sun, 21 Sep 2014 01:01:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 777F520176 for ; Sun, 21 Sep 2014 01:01:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751572AbaIUBBo (ORCPT ); Sat, 20 Sep 2014 21:01:44 -0400 Received: from mail-wg0-f47.google.com ([74.125.82.47]:47975 "EHLO mail-wg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751446AbaIUBBe (ORCPT ); Sat, 20 Sep 2014 21:01:34 -0400 Received: by mail-wg0-f47.google.com with SMTP id y10so1318388wgg.6 for ; Sat, 20 Sep 2014 18:01:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=surgut.co.uk; s=google; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ukfBLwlccTDPGQz9QRLpHdZCKWnRJVHy5Xx0dMxur78=; b=FpCm/U79Dw6qgN+4yarSGqVOA8PV22MgJFYz0mschB0mmTGygxT/hoXrXZekCUJYA/ +yPgkpYb0GfU1md2SHs/TIsFPcOct0o8kmKgV3eyl1sHgNgcEtVog2KTpe/GMvvV8Bs5 WjOW/9xBYlWLA38Ghcz/UCtCNKHSvUcQprU4I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=ukfBLwlccTDPGQz9QRLpHdZCKWnRJVHy5Xx0dMxur78=; b=gI9ooijrKdswhu/rjfj9JBuRSGKBKJHOldcvlHUhmFPhVObbNTODnZeYlNaGZm7HYa /u+Ouv6BVYPCCVQOGZK5qIzOvETvFeAb38uAtrXhxmjfETZdiAv8MkWiH+hxIsT8K1qU HNgUgWwqWW6sacxCdB3OGZ5LEkUinVq5aGVjjzUbuLCJsoTE2AlpnQVYM61q2XSIrV/k lw+uoFuT/dPo8iVEdS4p5chq6WgveF1S6olXJo3hOJ65Enm3eXiUwAHknwQJsKNT7Sbu uugUNVO+CofEId5NVdFCpQegJrIq0agvn5sHRWnZOSZWRlIRSvGezmMhUFBfIm5/LuIE 2Pbg== X-Gm-Message-State: ALoCoQk6vYhYo26YQdtCaF22I/t0R63wlqavqbpCBJL0eAYCSCAflFa1D4lx7hUdFenU0IiGJRLk X-Received: by 10.194.89.168 with SMTP id bp8mr10551068wjb.53.1411261292911; Sat, 20 Sep 2014 18:01:32 -0700 (PDT) Received: from localhost (cpc1-lewi13-2-0-cust98.2-4.cable.virginm.net. [86.14.120.99]) by mx.google.com with ESMTPSA id fv1sm7219716wjb.35.2014.09.20.18.01.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 Sep 2014 18:01:32 -0700 (PDT) From: Dimitri John Ledkov To: linux-btrfs@vger.kernel.org Cc: Shawn Landen , Dimitri John Ledkov Subject: [PATCH 3/4] Fixing unaligned memory accesses. Date: Sun, 21 Sep 2014 02:01:21 +0100 Message-Id: <1411261282-26831-3-git-send-email-xnox@debian.org> X-Mailer: git-send-email 2.1.0.rc1 In-Reply-To: <1411261282-26831-1-git-send-email-xnox@debian.org> References: <1411261282-26831-1-git-send-email-xnox@debian.org> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shawn Landen Bug-Debian: http://bugs.debian.org/656955 Signed-off-by: Dimitri John Ledkov --- 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 + #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;