From patchwork Thu Nov 21 21:15:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1199138 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uk4esRvu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47JsmG66czz9sQw for ; Fri, 22 Nov 2019 08:15:42 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 8DCF4C21F68; Thu, 21 Nov 2019 21:15:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 53885C21E53; Thu, 21 Nov 2019 21:15:32 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1746DC21E53; Thu, 21 Nov 2019 21:15:30 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by lists.denx.de (Postfix) with ESMTPS id B6ADBC21E35 for ; Thu, 21 Nov 2019 21:15:30 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id 4so2857738wro.7 for ; Thu, 21 Nov 2019 13:15:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=fu6nyAatYi+9frVtcZ66jdKTvLrcFrTMIr07khzZU6s=; b=uk4esRvuPF4fmJQCxwzbR0vaWe0C9RAsQRreWQEYRXk3VV0pgDy7Lkt82M+1B+4yoE tgNfSoQPFcpGUUzJIoAz1Yyh58SdpBHEfq4G9UgjqCCMk8fHuJy9bKxrVSXXvy5H98Tm W2sHL4RhIw6/2cuJFDjWDhV3dLvvSC3hiPgg36lSKma02tNAz5Sv6cPpPFNAkWiJlyOE yf47XRA995KTVAH3kHdNebUE6uTNzNs3u/QSumaVO8zuuaZS2+eVL1aptljWY++e2iVF lg+n5KrUYHZaHa/OCqQTLygbYAdF6+ndcUcvLo3dx8uoU8xeNpEyAZlnog9KPqHc4wpR aPqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=fu6nyAatYi+9frVtcZ66jdKTvLrcFrTMIr07khzZU6s=; b=e27SQKZnI7G9Cte2RlwUozz+PGbOVAA0WB2dXgoOsNnSAdSVvbaUnfMpG2ML8S/WU5 Q+Ixxk6regbwqdh2zyWNeBxC6d3rXVIBMgUn7A8JUUKiGaWXPYa7Fz6av6cE8WRbD+Gx xkJxF+cO2jVfamu+Bbtslpv7zW6ERFxT/nl2rsHl6PhCM7L/C+oIrRuesA9UQT8PTk5G QkxhR1n/uXelU/6OHJotYy+g0zVKyp2bngXL9jyRJMpEQwXctEELBQPT7P9ElHQDSTCD 5QwSuHh8ANwkIZ+HklQkEzqAgUNRayFxcxq1LfpRF/MaGIcy7/JwfUgEGlKaS27uX9jD rfBg== X-Gm-Message-State: APjAAAXQx490kdGJ7CXhUHMSLSNmRo26H4vm9ocydXbNfMPsCIS+lnJE 5GJI7NiRoEL6xcZPjTy0Y/8= X-Google-Smtp-Source: APXvYqzFlzKU+u6BsQJTExkG/ippr0GUa8selGo2wZKc/j5eHgMkxTQKastqiz+g0RLf3xmuAH1+TQ== X-Received: by 2002:adf:ea92:: with SMTP id s18mr12967388wrm.327.1574370930283; Thu, 21 Nov 2019 13:15:30 -0800 (PST) Received: from ubuntu.home ([2a02:8071:6a3:700:d43f:27ce:888:835]) by smtp.gmail.com with ESMTPSA id g138sm1055844wmg.11.2019.11.21.13.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 13:15:29 -0800 (PST) From: Simon Goldschmidt To: Marek Vasut Date: Thu, 21 Nov 2019 22:15:22 +0100 Message-Id: <20191121211523.7219-1-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Cc: Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 1/2] usb: composite: fix possible alignment issues X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Since upgrading to gcc9, warnings are issued: "taking address of packed member of ‘...’ may result in an unaligned pointer value" Fix this by converting two functions to use unaligned access since packed structures may be on an unaligned address, depending on USB hardware. Signed-off-by: Simon Goldschmidt Acked-by: Lukasz Majewski --- Changes in v2: - fix compiler warning "dereferencing ‘void *'" drivers/usb/gadget/composite.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 618a7d5016..c98a444245 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -12,8 +12,16 @@ #define USB_BUFSIZ 4096 +/* Helper type for accessing packed u16 pointers */ +typedef struct { __le16 val; } __packed __le16_packed; + static struct usb_composite_driver *composite; +static inline void le16_add_cpu_packed(__le16_packed *var, u16 val) +{ + var->val = cpu_to_le16(le16_to_cpu(var->val) + val); +} + /** * usb_add_function() - add a function to a configuration * @config: the configuration @@ -480,20 +488,21 @@ done: * the host side. */ -static void collect_langs(struct usb_gadget_strings **sp, __le16 *buf) +static void collect_langs(struct usb_gadget_strings **sp, void *buf) { const struct usb_gadget_strings *s; u16 language; - __le16 *tmp; + __le16_packed *tmp; + __le16_packed *end = (buf + 252); while (*sp) { s = *sp; language = cpu_to_le16(s->language); - for (tmp = buf; *tmp && tmp < &buf[126]; tmp++) { - if (*tmp == language) + for (tmp = buf; tmp->val && tmp < end; tmp++) { + if (tmp->val == language) goto repeat; } - *tmp++ = language; + tmp->val = language; repeat: sp++; } @@ -705,7 +714,8 @@ static int bos_desc(struct usb_composite_dev *cdev) */ usb_ext = cdev->req->buf + le16_to_cpu(bos->wTotalLength); bos->bNumDeviceCaps++; - le16_add_cpu(&bos->wTotalLength, USB_DT_USB_EXT_CAP_SIZE); + le16_add_cpu_packed((__le16_packed *)&bos->wTotalLength, + USB_DT_USB_EXT_CAP_SIZE); usb_ext->bLength = USB_DT_USB_EXT_CAP_SIZE; usb_ext->bDescriptorType = USB_DT_DEVICE_CAPABILITY; usb_ext->bDevCapabilityType = USB_CAP_TYPE_EXT; @@ -721,7 +731,8 @@ static int bos_desc(struct usb_composite_dev *cdev) ss_cap = cdev->req->buf + le16_to_cpu(bos->wTotalLength); bos->bNumDeviceCaps++; - le16_add_cpu(&bos->wTotalLength, USB_DT_USB_SS_CAP_SIZE); + le16_add_cpu_packed((__le16_packed *)&bos->wTotalLength, + USB_DT_USB_SS_CAP_SIZE); ss_cap->bLength = USB_DT_USB_SS_CAP_SIZE; ss_cap->bDescriptorType = USB_DT_DEVICE_CAPABILITY; ss_cap->bDevCapabilityType = USB_SS_CAP_TYPE;