From patchwork Fri Jun 10 15:00:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9169983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3E3DB607D9 for ; Fri, 10 Jun 2016 15:01:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3128728325 for ; Fri, 10 Jun 2016 15:01:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 247BB28368; Fri, 10 Jun 2016 15:01:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 80B9F28325 for ; Fri, 10 Jun 2016 15:01:05 +0000 (UTC) Received: from localhost ([::1]:41777 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBNvk-0001sq-I9 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 10 Jun 2016 11:01:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBNvT-0001sa-5t for qemu-devel@nongnu.org; Fri, 10 Jun 2016 11:00:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bBNvS-0006QE-9E for qemu-devel@nongnu.org; Fri, 10 Jun 2016 11:00:47 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:57627) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bBNvS-0006Om-1G for qemu-devel@nongnu.org; Fri, 10 Jun 2016 11:00:46 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bBNvJ-0002BQ-0x; Fri, 10 Jun 2016 16:00:37 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 10 Jun 2016 16:00:36 +0100 Message-Id: <1465570836-22211-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] 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: Paolo Bonzini , patches@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Eric Blake --- The motivation is to be able to drop *_to_cpup() entirely; we don't have many places that use it. --- nbd/client.c | 8 ++++---- nbd/server.c | 10 +++++----- qemu-nbd.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) 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,