Received: by 10.213.65.68 with SMTP id h4csp744539imn; Fri, 6 Apr 2018 08:11:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+99oTXCH7h3mzqP+1KVpRfFSZemC3oSaCbJ0xarxo29MYNZmO/0Jd9cb3heRoY/iwvfDVJ X-Received: by 10.167.130.146 with SMTP id s18mr8249050pfm.236.1523027471285; Fri, 06 Apr 2018 08:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523027471; cv=none; d=google.com; s=arc-20160816; b=fuG9u9zc2NQmr2Eo9+K/XxEkxKyAxUuZgHMJ4rdCZhodEEm1RADMAWg1hrLTgDl8S7 wF8DIqcxp+CMZsP/W4UnVZLZoAahvVQqdUPfWbYpXefnqmnvJq5Lfvx6BDOVmhhWOFVL L/PrgeXFspAiHD3sRxJU8DC6JdyXuqqIRQH/SlKdfjgjzCgpj9IQNjpqknPUQOPszNf0 uY/kLFTcb01go7AjkqS8gwjqXFkUu99y3+Dx3t+SbI/FZ/w6LRKfyJ19mjTU6U7kjFzE rgcSpJMB2o7/Q2qGGGBarsCrJlbKkzM9gKy8zVqOqfNXhjLZK7Eknt7LcohvPAb2erE6 a0sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=e3uWem1aX0dHq4m4dRAIU+CxEYHmLbCQ8wXzJOK3euM=; b=j1+/cKJ5H6ojRPHE1u4navmS2t/bqY4dfP0coMyBwRuePFf6Uh2BY6RkVlUj6dYuaW 8OTBtSXKXAdTn+oiKffa0/sseNtZIpRhHRvjq3TSfefn7XRslmuO+f3yM5/IvD6L5wme dKPHgqs18BG3aEbLWN1Dw5BgJ0FKvwu3YtaMQaHSzvLwWHAr1Dyf7rYXiZ/2agi6qUi0 utcKyZBFDaRFrzY9h4/hSARAD8TNQFK+MBUw4AUUe/JqU792Ay8N6NpYYdHToURNHb3v EMLgrffOE82sv8NNg1dHdbjEDQsqtdHG+qFQOa7FkCXQkaq6givE0CW1gY1IavZvO8wF j0wQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9-v6si8286829pls.485.2018.04.06.08.10.57; Fri, 06 Apr 2018 08:11:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754691AbeDFN3n (ORCPT + 99 others); Fri, 6 Apr 2018 09:29:43 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55884 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754677AbeDFN3l (ORCPT ); Fri, 6 Apr 2018 09:29:41 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A88DDD36; Fri, 6 Apr 2018 13:29:40 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Felipe F. Tonello" , Felipe Balbi Subject: [PATCH 4.4 08/72] usb: gadget: fix usb_ep_align_maybe endianness and new usb_ep_align Date: Fri, 6 Apr 2018 15:23:09 +0200 Message-Id: <20180406084305.796067391@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084305.210085169@linuxfoundation.org> References: <20180406084305.210085169@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Felipe F. Tonello commit 16b114a6d7973cf027e4c2b23eae1076eaf98c25 upstream. USB spec specifies wMaxPacketSize to be little endian (as other properties), so when using this variable in the driver we should convert to the current CPU endianness if necessary. This patch also introduces usb_ep_align() which does always returns the aligned buffer size for an endpoint. This is useful to be used by USB requests allocator functions. Signed-off-by: Felipe F. Tonello Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- include/linux/usb/gadget.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -663,8 +663,20 @@ static inline struct usb_gadget *dev_to_ list_for_each_entry(tmp, &(gadget)->ep_list, ep_list) /** + * usb_ep_align - returns @len aligned to ep's maxpacketsize. + * @ep: the endpoint whose maxpacketsize is used to align @len + * @len: buffer size's length to align to @ep's maxpacketsize + * + * This helper is used to align buffer's size to an ep's maxpacketsize. + */ +static inline size_t usb_ep_align(struct usb_ep *ep, size_t len) +{ + return round_up(len, (size_t)le16_to_cpu(ep->desc->wMaxPacketSize)); +} + +/** * usb_ep_align_maybe - returns @len aligned to ep's maxpacketsize if gadget - * requires quirk_ep_out_aligned_size, otherwise reguens len. + * requires quirk_ep_out_aligned_size, otherwise returns len. * @g: controller to check for quirk * @ep: the endpoint whose maxpacketsize is used to align @len * @len: buffer size's length to align to @ep's maxpacketsize @@ -675,8 +687,7 @@ static inline struct usb_gadget *dev_to_ static inline size_t usb_ep_align_maybe(struct usb_gadget *g, struct usb_ep *ep, size_t len) { - return !g->quirk_ep_out_aligned_size ? len : - round_up(len, (size_t)ep->desc->wMaxPacketSize); + return g->quirk_ep_out_aligned_size ? usb_ep_align(ep, len) : len; } /**