From patchwork Fri Aug 3 09:03:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Spirkov X-Patchwork-Id: 10554795 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 71C1715A6 for ; Fri, 3 Aug 2018 09:03:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6185F2BAB2 for ; Fri, 3 Aug 2018 09:03:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 537A62BE81; Fri, 3 Aug 2018 09:03:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0F432BAB2 for ; Fri, 3 Aug 2018 09:03:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731342AbeHCK7P (ORCPT ); Fri, 3 Aug 2018 06:59:15 -0400 Received: from mail-eopbgr80075.outbound.protection.outlook.com ([40.107.8.75]:28448 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732247AbeHCK7P (ORCPT ); Fri, 3 Aug 2018 06:59:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=astrosoftrus.onmicrosoft.com; s=selector1-astrosoft-ru; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oMEg9CRc/wkcWKInT6PlBmzhe34lw7dZj0Ou8pZ1pv0=; b=Ka7Sp34Y6EiFavkDrFbKrfUsRR+6iLppFdMoi0fHSF6p2RlO+fn0rbHHeRvSQ+PI/Y1Baac1FfMAS21ryIcN1F4pLIIMja2p4fatsLyDsqSATW5/cemqxLsn18hzrS2qciUgcdDxyymiUM8LJdECeSQAcEetKOeIO512PXyjW8U= Received: from HE1PR0301MB2442.eurprd03.prod.outlook.com (10.168.124.21) by HE1PR0301MB1963.eurprd03.prod.outlook.com (10.167.188.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.14; Fri, 3 Aug 2018 09:03:36 +0000 Received: from HE1PR0301MB2442.eurprd03.prod.outlook.com ([fe80::3c31:8066:fd43:98f]) by HE1PR0301MB2442.eurprd03.prod.outlook.com ([fe80::3c31:8066:fd43:98f%4]) with mapi id 15.20.1017.010; Fri, 3 Aug 2018 09:03:36 +0000 From: Alexey Spirkov To: Bin Liu , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" CC: "andrew@ncrmnt.org" Subject: [PATCH v2] usb: musb: gadget: Fix big-endian arch issue Thread-Topic: [PATCH v2] usb: musb: gadget: Fix big-endian arch issue Thread-Index: AdQrCNvb70jAUIF2QyWT3Ci8mRZ5ig== Date: Fri, 3 Aug 2018 09:03:36 +0000 Message-ID: Accept-Language: en-US, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=AlexeiS@astrosoft.ru; x-originating-ip: [195.190.96.106] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;HE1PR0301MB1963;6:JfA+guPdE6/ZuqmFLZYS82/YcUqAqvvAe7XqiOtCabT+eeh4sJdgwOiPe3Znrg3VPrPtwmb8G/SaTvBWoAe3FGxKeXe8zIBZDAfhQXENk+JMiVJFeqCDhatQfRvJNwFOvmCWWHPZSNxY7/na8JGDnV1IqytoFnJ65LXfaS7wyCOI5IBQBzSpkOgUoGqkaL4xk5KZcEvqkb7/rGus5M+gBrtxssNHZ+XmSiwlQ/ZdYEPV3rkhwji8IGQ6v6DtiBmVnVVJ8x7uOksGTwmOREGY9I3hN3R772/DS+hVuSN/2TKk6eh8faTrbKm2OQz8FHIxk0HPcDzlUenIkS2FhKVeOUS4NaE3OMjJ4cv06VkrqM7a/tdzareDXlL+LNqB3DdSJFhb7jyRS38dUM1ZFVAyt9uzi8syr9Kd5oITTyNP5/a1bv58lBxb9fOb7ZvmAKurcEcHmhSyJYHBXNAxiLTZQg==;5:KmEOofBlacOqJVmgn/Z2UYcbEhbAXl/X73fr9KXQ0vP2aA1Mgp5G/PzM/QJxngEnyTRg96HGj7Mo7i2Sc2oWDiVdcQbKA4VxdTOWnQYH3mWDUihaOFcHcZxIML9y5SQxKH+IWoUDNjmeMUal1ODiveGLG4vzneLeJf8hz1hgIgY=;7:GIFpLiDxLW1prQecr10dlZGV3k8UlUQR/teEHygwML/7uN9RdQat4Lfy4NXEfkY8LN4lSURWObIacx0kLEINrqDZ8/uuoReH/NGQRzLdTzJllF1vwAH/1u3GGXZY/E6OCVKAEDUfdkiT6PbtR4h+prUUWkFJ1+u2RAb60Xp6MMVNzbuhWrXZEPcxIXIaCqPa9ULb4MIih2eKHdE7XImFMWpWqNfN2tiwkpKDlgIjH6YIYw1V2+SxB8r0YhaPhu26 x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: d59c6b03-c531-4f3d-e4c8-08d5f91fff4f x-microsoft-antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(7021125)(8989117)(5600074)(711020)(4534165)(7022125)(4603075)(4627221)(201702281549075)(8990107)(7048125)(7024125)(7027125)(7028125)(7023125)(2017052603328)(7153060)(7193020);SRVR:HE1PR0301MB1963; x-ms-traffictypediagnostic: HE1PR0301MB1963: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231311)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(20161123564045)(20161123560045)(20161123558120)(2016111802025)(20161123562045)(6072148)(6043046)(201708071742011)(7699016);SRVR:HE1PR0301MB1963;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0301MB1963; x-forefront-prvs: 0753EA505A x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(396003)(366004)(346002)(376002)(136003)(39840400004)(189003)(199004)(256004)(7736002)(68736007)(5250100002)(74316002)(86362001)(8936002)(66066001)(2501003)(305945005)(105586002)(3846002)(106356001)(2906002)(25786009)(14444005)(6116002)(575784001)(9686003)(74482002)(4477795004)(478600001)(476003)(14454004)(81166006)(72206003)(55016002)(6436002)(7696005)(110136005)(6506007)(81156014)(8676002)(53936002)(5660300001)(4326008)(80792005)(2900100001)(97736004)(102836004)(486006)(186003)(316002)(81472002)(26005)(33656002)(99286004);DIR:OUT;SFP:1101;SCL:1;SRVR:HE1PR0301MB1963;H:HE1PR0301MB2442.eurprd03.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: astrosoft.ru does not designate permitted sender hosts) x-microsoft-antispam-message-info: pZEc70Ws1wHUkQfkkO/eibpYxDJYquB0j2evVpv2fc9IO7Y1HMJ7ekScHg9rovd5P7DCVYnc+3uwRpuy0JYV+QtVAuI4NXwkp8zbVjA0LTYqvs9xIOpKs9yutm/v1zWjDxeROUP5gZW3N/qZogL71G21k/Rn0lFUzV2dIGS7K7r+eaYj4GR9Ez+8hcNt210oJMtLxAihzmiJgfdtFOAOEPhp3fgFr5OwSieNtgUG96m8FGOd1XPlNwIe69aQJEue9sRpWdVOGfWpESfu7ItJdt0aZ2N++KuhKGpkQTwMAJlPbsZJMmr7b94GCHvQ+jMf6iSzQ10mE3g2ykD0PWRWmn+FwlFCBdJNVBYQu1CopRw= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: astrosoft.ru X-MS-Exchange-CrossTenant-Network-Message-Id: d59c6b03-c531-4f3d-e4c8-08d5f91fff4f X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Aug 2018 09:03:36.4770 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5e87efa3-43e9-482d-a930-52632921709f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0301MB1963 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Existing code is not applicable to big-endian machines ctrlrequest fields received in USB endian - i.e. in little-endian and should be converted to cpu endianness before usage. Signed-off-by: Alexey Spirkov --- drivers/usb/musb/musb_gadget_ep0.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) -- 2.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c index 91a5027..90abacb 100644 --- a/drivers/usb/musb/musb_gadget_ep0.c +++ b/drivers/usb/musb/musb_gadget_ep0.c @@ -82,7 +82,7 @@ static int service_tx_status_request( u16 tmp; void __iomem *regs; - epnum = (u8) ctrlrequest->wIndex; + epnum = (u8) le16_to_cpu(ctrlrequest->wIndex); if (!epnum) { result[0] = 0; break; @@ -209,6 +209,8 @@ __acquires(musb->lock) int handled = -EINVAL; void __iomem *mbase = musb->mregs; const u8 recip = ctrlrequest->bRequestType & USB_RECIP_MASK; + u16 reqval = le16_to_cpu(ctrlrequest->wValue); + u16 reqidx = le16_to_cpu(ctrlrequest->wIndex); /* the gadget driver handles everything except what we MUST handle */ if ((ctrlrequest->bRequestType & USB_TYPE_MASK) @@ -217,15 +219,14 @@ __acquires(musb->lock) case USB_REQ_SET_ADDRESS: /* change it after the status stage */ musb->set_address = true; - musb->address = (u8) (ctrlrequest->wValue & 0x7f); + musb->address = (u8) (reqval & 0x7f); handled = 1; break; case USB_REQ_CLEAR_FEATURE: switch (recip) { case USB_RECIP_DEVICE: - if (ctrlrequest->wValue - != USB_DEVICE_REMOTE_WAKEUP) + if (reqval != USB_DEVICE_REMOTE_WAKEUP) break; musb->may_wakeup = 0; handled = 1; @@ -233,8 +234,7 @@ __acquires(musb->lock) case USB_RECIP_INTERFACE: break; case USB_RECIP_ENDPOINT:{ - const u8 epnum = - ctrlrequest->wIndex & 0x0f; + const u8 epnum = reqidx & 0x0f; struct musb_ep *musb_ep; struct musb_hw_ep *ep; struct musb_request *request; @@ -243,12 +243,12 @@ __acquires(musb->lock) u16 csr; if (epnum == 0 || epnum >= MUSB_C_NUM_EPS || - ctrlrequest->wValue != USB_ENDPOINT_HALT) + reqval != USB_ENDPOINT_HALT) break; ep = musb->endpoints + epnum; regs = ep->regs; - is_in = ctrlrequest->wIndex & USB_DIR_IN; + is_in = reqidx & USB_DIR_IN; if (is_in) musb_ep = &ep->ep_in; else @@ -300,17 +300,17 @@ __acquires(musb->lock) switch (recip) { case USB_RECIP_DEVICE: handled = 1; - switch (ctrlrequest->wValue) { + switch (reqval) { case USB_DEVICE_REMOTE_WAKEUP: musb->may_wakeup = 1; break; case USB_DEVICE_TEST_MODE: if (musb->g.speed != USB_SPEED_HIGH) goto stall; - if (ctrlrequest->wIndex & 0xff) + if (reqidx & 0xff) goto stall; - switch (ctrlrequest->wIndex >> 8) { + switch (reqidx >> 8) { case 1: pr_debug("TEST_J\n"); /* TEST_J */ @@ -398,8 +398,7 @@ __acquires(musb->lock) break; case USB_RECIP_ENDPOINT:{ - const u8 epnum = - ctrlrequest->wIndex & 0x0f; + const u8 epnum = reqidx & 0x0f; struct musb_ep *musb_ep; struct musb_hw_ep *ep; void __iomem *regs; @@ -407,12 +406,12 @@ __acquires(musb->lock) u16 csr; if (epnum == 0 || epnum >= MUSB_C_NUM_EPS || - ctrlrequest->wValue != USB_ENDPOINT_HALT) + reqval != USB_ENDPOINT_HALT) break; ep = musb->endpoints + epnum; regs = ep->regs; - is_in = ctrlrequest->wIndex & USB_DIR_IN; + is_in = reqidx & USB_DIR_IN; if (is_in) musb_ep = &ep->ep_in; else