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; From patchwork Thu Nov 21 21:15:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Goldschmidt X-Patchwork-Id: 1199139 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="DLRUnWAi"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47Jsmt0DYrz9sPJ for ; Fri, 22 Nov 2019 08:16:14 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C205FC21FBB; Thu, 21 Nov 2019 21:15:49 +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 C45D9C21FBF; Thu, 21 Nov 2019 21:15:48 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8CD7CC21FE4; Thu, 21 Nov 2019 21:15:38 +0000 (UTC) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by lists.denx.de (Postfix) with ESMTPS id 05B60C21F8C for ; Thu, 21 Nov 2019 21:15:36 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id z19so5353323wmk.3 for ; Thu, 21 Nov 2019 13:15:36 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=JW24aMFtghBBjneiUMffIWmafGq7YNPLxOlyodKDSNo=; b=DLRUnWAir7UYEFk6wwoZBWDBMGkF/kS+iAGZMv6tLQGqcdKf1Hy0Ch7yRsixmJNyBS SKJI6MmVu6lJg09kn7a3PJPP8PZFTONnvsCx28GVE5TiCAEGUT9Gx7VUqCAVskia19fb BqhFIONFkpsR7UTLYPD84O8mgIdDgI+p7wmk6+EFxQak8PZrdgR+YSEkT2o6AeSdEPQX N2uj+66UyV0kV2U52+UGjg4+CuUl12FL833iuhnDAfRmzC678JcGSlZpXCs0O0uUvP/n w3rKMWYFQVSvVqQQKK26dl3yOurhJ1uwf/bhQyrH6g7PcbBOrllELjYIA6fSwEWvO8fD A1og== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=JW24aMFtghBBjneiUMffIWmafGq7YNPLxOlyodKDSNo=; b=YVh7zLw99I8w+XquiUraPlDy0HBtsaw5uzEZYAaJDQStlXTk+0+vPfTvJO1OrN9Rvx c4RLUQsQVQfDxRR731MVZu5eNSY/RwVp73uyzUenv2CGTGtWPSy7rzkpg/uZurNSrrgy f2k0YDve/IAayJjci7IoxvClaRZDok9ZSwsdJzukrp3RptlLOe320hh/9iG2JfsdUiYb yFjSa7YUUFh0yIvKfFBnmn+02k8WUBpBbZGOAJn4uWpAvy1OYLz531YYpKhTXcUGC9X4 GvF+OeVIxcKpWvcxgpAbJexRLpmKvj57puHGDLWBbWTheFz9dJPQoHPHTomiQDj7hntI ZIww== X-Gm-Message-State: APjAAAUqsJJTOuOnMPtaIhsXiR0kIq9mtOcrQzYpwcZCT5Pfg93OUx5e IaqI+EihMpWFKGCkwyJn1es= X-Google-Smtp-Source: APXvYqyH3HZyL5brGYey7HK+W5PCRFbMOLhSathUZrM/5cSoNmN+tqkXV7uHeqhhszp2ZR2+3nUW3g== X-Received: by 2002:a05:600c:2103:: with SMTP id u3mr13405879wml.150.1574370935642; Thu, 21 Nov 2019 13:15:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2019 13:15:35 -0800 (PST) From: Simon Goldschmidt To: Marek Vasut Date: Thu, 21 Nov 2019 22:15:23 +0100 Message-Id: <20191121211523.7219-2-simon.k.r.goldschmidt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191121211523.7219-1-simon.k.r.goldschmidt@gmail.com> References: <20191121211523.7219-1-simon.k.r.goldschmidt@gmail.com> MIME-Version: 1.0 Cc: Heinrich Schuchardt , u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 2/2] usb: dwc2: 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 dwc2_fifo_read 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: None drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c index 7eb632d3b1..dba221dad0 100644 --- a/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c +++ b/drivers/usb/gadget/dwc2_udc_otg_xfer_dma.c @@ -731,7 +731,7 @@ static int write_fifo_ep0(struct dwc2_ep *ep, struct dwc2_request *req) return 0; } -static int dwc2_fifo_read(struct dwc2_ep *ep, u32 *cp, int max) +static int dwc2_fifo_read(struct dwc2_ep *ep, void *cp, int max) { invalidate_dcache_range((unsigned long)cp, (unsigned long)cp + ROUND(max, CONFIG_SYS_CACHELINE_SIZE)); @@ -1285,7 +1285,7 @@ static void dwc2_ep0_setup(struct dwc2_udc *dev) nuke(ep, -EPROTO); /* read control req from fifo (8 bytes) */ - dwc2_fifo_read(ep, (u32 *)usb_ctrl, 8); + dwc2_fifo_read(ep, usb_ctrl, 8); debug_cond(DEBUG_SETUP != 0, "%s: bRequestType = 0x%x(%s), bRequest = 0x%x"