From patchwork Thu Jun 16 14:16:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 70191 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp306492qgy; Thu, 16 Jun 2016 07:59:35 -0700 (PDT) X-Received: by 10.140.100.240 with SMTP id s103mr5308943qge.39.1466089175111; Thu, 16 Jun 2016 07:59:35 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id c130si24324255qkb.126.2016.06.16.07.59.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 16 Jun 2016 07:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:49886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDYla-00076s-IW for patch@linaro.org; Thu, 16 Jun 2016 10:59:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDY67-0006n5-UR for qemu-devel@nongnu.org; Thu, 16 Jun 2016 10:16:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDY66-00030r-Pa for qemu-devel@nongnu.org; Thu, 16 Jun 2016 10:16:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55194) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDY66-00030n-Gm for qemu-devel@nongnu.org; Thu, 16 Jun 2016 10:16:42 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D1BD80096; Thu, 16 Jun 2016 14:16:42 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-58.ams2.redhat.com [10.36.112.58]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5GEGQgi016497; Thu, 16 Jun 2016 10:16:41 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 16 Jun 2016 16:16:04 +0200 Message-Id: <1466086585-16526-10-git-send-email-pbonzini@redhat.com> In-Reply-To: <1466086585-16526-1-git-send-email-pbonzini@redhat.com> References: <1466086585-16526-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 16 Jun 2016 14:16:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 09/30] nbd: Don't use *_to_cpup() functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell The *_to_cpup() functions are not very useful, as they simply do a pointer dereference and then a *_to_cpu(). Instead use either: * ld*_*_p(), if the data is at an address that might not be correctly aligned for the load * a local dereference and *_to_cpu(), if the pointer is the correct type and known to be correctly aligned Signed-off-by: Peter Maydell Message-Id: <1465570836-22211-1-git-send-email-peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini --- nbd/client.c | 8 ++++---- nbd/server.c | 10 +++++----- qemu-nbd.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) -- 2.5.5 diff --git a/nbd/client.c b/nbd/client.c index 31b88f3..bb8981f 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -572,7 +572,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags, error_setg(errp, "Failed to read export flags"); goto fail; } - *flags = be32_to_cpup(flags); + *flags = be32_to_cpu(*flags); } else { error_setg(errp, "Bad magic received"); goto fail; @@ -726,9 +726,9 @@ ssize_t nbd_receive_reply(QIOChannel *ioc, struct nbd_reply *reply) [ 7 .. 15] handle */ - magic = be32_to_cpup((uint32_t*)buf); - reply->error = be32_to_cpup((uint32_t*)(buf + 4)); - reply->handle = be64_to_cpup((uint64_t*)(buf + 8)); + magic = ldl_be_p(buf); + reply->error = ldl_be_p(buf + 4); + reply->handle = ldq_be_p(buf + 8); reply->error = nbd_errno_to_system_errno(reply->error); diff --git a/nbd/server.c b/nbd/server.c index b2cfeb9..91471f1 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -646,11 +646,11 @@ static ssize_t nbd_receive_request(QIOChannel *ioc, struct nbd_request *request) [24 .. 27] len */ - magic = be32_to_cpup((uint32_t*)buf); - request->type = be32_to_cpup((uint32_t*)(buf + 4)); - request->handle = be64_to_cpup((uint64_t*)(buf + 8)); - request->from = be64_to_cpup((uint64_t*)(buf + 16)); - request->len = be32_to_cpup((uint32_t*)(buf + 24)); + magic = ldl_be_p(buf); + request->type = ldl_be_p(buf + 4); + request->handle = ldq_be_p(buf + 8); + request->from = ldq_be_p(buf + 16); + request->len = ldl_be_p(buf + 24); TRACE("Got request: " "{ magic = 0x%x, .type = %d, from = %" PRIu64" , len = %u }", diff --git a/qemu-nbd.c b/qemu-nbd.c index 6554f0a..9519db3 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -154,8 +154,8 @@ static void read_partition(uint8_t *p, struct partition_record *r) r->end_cylinder = p[7] | ((p[6] << 2) & 0x300); r->end_sector = p[6] & 0x3f; - r->start_sector_abs = le32_to_cpup((uint32_t *)(p + 8)); - r->nb_sectors_abs = le32_to_cpup((uint32_t *)(p + 12)); + r->start_sector_abs = ldl_le_p(p + 8); + r->nb_sectors_abs = ldl_le_p(p + 12); } static int find_partition(BlockBackend *blk, int partition,