From patchwork Fri Mar 29 11:11:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 1069472 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44VzpV3Hlcz9sPB for ; Fri, 29 Mar 2019 22:21:54 +1100 (AEDT) Received: from localhost ([127.0.0.1]:51002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pa4-0004dJ-BG for incoming@patchwork.ozlabs.org; Fri, 29 Mar 2019 07:21:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:49302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9pQj-0003yV-GP for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9pQf-0001N2-JX for qemu-devel@nongnu.org; Fri, 29 Mar 2019 07:12:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44962) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9pQf-0001DI-9Q; Fri, 29 Mar 2019 07:12:09 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 809E086673; Fri, 29 Mar 2019 11:12:07 +0000 (UTC) Received: from dhcp-17-117.lcy.redhat.com (unknown [10.42.17.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 131E760BFB; Fri, 29 Mar 2019 11:12:04 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 11:11:00 +0000 Message-Id: <20190329111104.17223-11-berrange@redhat.com> In-Reply-To: <20190329111104.17223-1-berrange@redhat.com> References: <20190329111104.17223-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 29 Mar 2019 11:12:07 +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] [PATCH 10/14] usb-mtp: avoid warning about unaligned access to filename 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: Eric Farman , Farhan Ali , David Hildenbrand , Cornelia Huck , Alex Williamson , Laurent Vivier , Halil Pasic , Max Filippov , qemu-s390x@nongnu.org, Gerd Hoffmann , Thomas Huth , Riku Voipio , Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The 'filename' field in ObjectInfo struct is declared as a zero length array of uint16_t. Accessing it is equivalent to taking the address of the field, and taking the address of fields in a packed struct causes unaligned pointer warnings: hw/usb/dev-mtp.c: In function ‘usb_mtp_write_metadata’: hw/usb/dev-mtp.c:1712:36: warning: taking address of packed member of ‘struct ’ may result in an unaligned pointer value [-Waddress-of-packed-member] 1712 | dataset->filename); | ~~~~~~~^~~~~~~~~~ The warning is in fact correct because the 'filename' field is preceeded by a uint8_t field which causes it to have bad alignment. Using pointer arithmetic instead of accessing the zero length array field directly avoids the compiler warning but doesn't ultimately fix the bad alignment. Fixing that probably requires allocating a new array of uint16_t in the heap & then memcpy() the data before accessing the array elements. Signed-off-by: Daniel P. Berrangé --- hw/usb/dev-mtp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c index 5343449663..9ddcfbe7a6 100644 --- a/hw/usb/dev-mtp.c +++ b/hw/usb/dev-mtp.c @@ -225,7 +225,7 @@ typedef struct { uint16_t assoc_type; uint32_t assoc_desc; uint32_t seq_no; /*unused*/ - uint8_t length; /*part of filename field*/ + uint8_t length; /*length of filename field*/ uint16_t filename[0]; char date_created[0]; /*unused*/ char date_modified[0]; /*unused*/ @@ -1703,13 +1703,15 @@ static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen) MTPObject *o; MTPObject *p = usb_mtp_object_lookup(s, s->dataset.parent_handle); uint32_t next_handle = s->next_handle; + uint16_t *wfilename = (uint16_t *)(d->data + + offsetof(ObjectInfo, filename)); assert(!s->write_pending); assert(p != NULL); filename = utf16_to_str(MIN(dataset->length, dlen - offsetof(ObjectInfo, filename)), - dataset->filename); + wfilename); if (strchr(filename, '/')) { usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,