Received: by 10.213.65.68 with SMTP id h4csp760551imn; Fri, 6 Apr 2018 08:26:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx488+EzsD8mTRZX9C6zmOuf7eDStqWvhmswJCI72Q2mXZFMeUfctLBia14of+Nmtbqk1/ZYW X-Received: by 10.98.15.92 with SMTP id x89mr20954045pfi.7.1523028403751; Fri, 06 Apr 2018 08:26:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523028403; cv=none; d=google.com; s=arc-20160816; b=Ts3QQcrjfCc+yZJQJ/rYRqmtqeFvAJrt8/Afv+buICUuQgq3RggS9H8B9yfvkvySwb HaogFoH5IbtbHCPO0ap5nTVW/+cmhCwcaw/ZKsCZD2uqMRMQ3HE9agsRdajaQ7c2iEZ2 KioSXHEE6pOzWlpAiQS7L75FHSHb1VJYR29djLeKKEzU3xb8QYaegcob5IPcZczhA2Jc 077s+2SFMOzmJqY8i13uLsankr6g3zCLatMi2Ky/VUhPArQETNDsO2CMKsyGuk3T2kU+ NSsovClP6XF9VlTdKupD2LsrOFdL2l1BmlLJF37NRz6Fd0EOHZrx4FLFdZBbsdVzSXKy ioOQ== 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=tJ3TGUCsJTAsFYZx716Zj2WBnVO18xgE8LBiw1NUIzM=; b=irt6XxjAMFdfL+Tzv5uZcBEE/VE2RsZokzF+Cmfi7Tf/5FRaVg7H/bl5/kEyH3nXKG ToZmoKPCIDc7VAZK+dCns76fYl0cpL6IOqpNxxFoznewqWgTwsIUVXL5TjJa2kK1ZvDV DV5wBlIxGoLqDeXhekYzOXVBFgUSNoUnv88VoVpzZ3+OxXD4jTfUHVvYLP26CpLzFGjN ju7cLt/1iClZfWEip+oSf9Gqo8rkUOjjpPv+Z5/2a+vXeef6ACeqUQtEYTj0CzQml0Qd BQ6E3buN5ub5rSJBFUwN6z6dOPIfVb1WOPOtp0JUSGm3+H8Rpj46vPDhB8lagHYI5a7P EaBg== 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 j8-v6si10183929pli.9.2018.04.06.08.26.30; Fri, 06 Apr 2018 08:26:43 -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 S1754057AbeDFN0t (ORCPT + 99 others); Fri, 6 Apr 2018 09:26:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54758 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752639AbeDFN0q (ORCPT ); Fri, 6 Apr 2018 09:26:46 -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 4EE3A42B; Fri, 6 Apr 2018 13:26:45 +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 3.18 44/93] usb: gadget: fix usb_ep_align_maybe endianness and new usb_ep_align Date: Fri, 6 Apr 2018 15:23:13 +0200 Message-Id: <20180406084226.848881058@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084224.918716300@linuxfoundation.org> References: <20180406084224.918716300@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 3.18-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 @@ -582,8 +582,20 @@ static inline struct usb_gadget *dev_to_ /** + * 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 @@ -594,8 +606,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; } /**