From patchwork Mon Mar 27 17:59:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 96091 Delivered-To: patches@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1340240qgd; Mon, 27 Mar 2017 10:59:08 -0700 (PDT) X-Received: by 10.223.136.182 with SMTP id f51mr10244805wrf.134.1490637548284; Mon, 27 Mar 2017 10:59:08 -0700 (PDT) Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id a22si1606076wra.276.2017.03.27.10.59.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 10:59:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1csYv3-0000ac-2r; Mon, 27 Mar 2017 18:59:05 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, "Aneesh Kumar K.V" , Greg Kurz Subject: [PATCH for-2.9] tests/virtio-9p-test: Don't call le*_to_cpus on fields of packed struct Date: Mon, 27 Mar 2017 18:59:04 +0100 Message-Id: <1490637544-15650-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.7.4 For a packed struct like 'P9Hdr' the fields within it may not be aligned as much as the natural alignment for their types. This means it is not valid to pass the address of such a field to a function like le32_to_cpus() which operate on uint32_t* and assume alignment. Doing this results in a SIGBUS on hosts like SPARC which have strict alignment requirements. Use ldl_le_p() instead, which is specified to correctly handle unaligned pointers. Signed-off-by: Peter Maydell --- Sadly gcc doesn't warn about this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51628 clang supposedly was fixed to do so: https://bugs.llvm.org//show_bug.cgi?id=22821 but I think that commit was reverted without the bug being reopened; at least my clang doesn't have that warning flag. --- tests/virtio-9p-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.7.4 Reviewed-by: Greg Kurz diff --git a/tests/virtio-9p-test.c b/tests/virtio-9p-test.c index 43a1ad8..ad33d96 100644 --- a/tests/virtio-9p-test.c +++ b/tests/virtio-9p-test.c @@ -256,8 +256,8 @@ static void v9fs_req_recv(P9Req *req, uint8_t id) qvirtio_wait_queue_isr(v9p->dev, v9p->vq, 1000 * 1000); v9fs_memread(req, &hdr, 7); - le32_to_cpus(&hdr.size); - le16_to_cpus(&hdr.tag); + hdr.size = ldl_le_p(&hdr.size); + hdr.tag = lduw_le_p(&hdr.tag); if (hdr.size >= 7) { break; }