Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2561240imu; Thu, 29 Nov 2018 06:56:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/V76rknKaZufNr/m1S1rmeL/CXC3rv0GKTV4TlAzAynPobns0nLAQfANM6VpCHyyH1aLzAs X-Received: by 2002:a17:902:8687:: with SMTP id g7mr1773256plo.96.1543503387497; Thu, 29 Nov 2018 06:56:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543503387; cv=none; d=google.com; s=arc-20160816; b=SzVTZdqFMN8JuBPL6fLRrsVj9Q3klsMudR2395x9b1GMDZdzI9Vv1zoDY0sZwJvdGm Bu9oJSu91mYgkW2qcPkPc1WSEi+dq6sFAla1glpvRZvm2wHVDWFPNIC2bbajgtVQSdSc xxq+7j4xO/8bnX8c8lEr0/xEBGglxadGAzMirBS15Q6lAusWhccMvqzx4Y9wOTmwruoz gAnnm6pYjcgBVw5Jc4hza3ycr+Dg8rOz/OT2AmHKbVAB+Ag7BYRZYL2miicuyEGletGw ImbvQIppYMU+ZdO1HJXW57HvmOLAhqQPIiEcU1UeKykeUocQ4JGp3FdPq6d/cjcj8sjO lIQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2DnL4spr+Ljpnju8lRV5zZtpZvGr+wW2CuQNg1hRIEI=; b=sa/N8bCrC1x5b2q9CGSFS2eOYbPA7F27PL7CoD66VZDcoZaWeDhy9rfkjOaJaAHpRo USol2qQcizcYLZ4fTsxmyo2wooKpnExXtupX5d3xG/S7bbo4QcBmBaHgQxzvIlc8v35Z vtgZpQwOe9bk7ze93rqOXfblPal2SVdgj1kJLB7WzDHQ4tE5RL+Lm628yelRRpc2y5nG O2+Tq+NMzrWuW8UgAN57UUwpdKvG7yvrkW2lTJ+8FTgXMXxcr3dkZ21G/mLtAJV79KAs lJioo+UwjuqGbUyReHjEy7u3pXIO4hfwsPcNarsbqnoJwuENJ1rtsjZWiwew7nrLCtfh loCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=acLlAvE3; 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 i20si2211955pgh.187.2018.11.29.06.56.12; Thu, 29 Nov 2018 06:56:27 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=acLlAvE3; 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 S1731970AbeK3B16 (ORCPT + 99 others); Thu, 29 Nov 2018 20:27:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:53256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731259AbeK3B14 (ORCPT ); Thu, 29 Nov 2018 20:27:56 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CF69A205C9; Thu, 29 Nov 2018 14:22:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543501345; bh=9cggRxTwxnfGISkLIpMgjiuroqzD/sayQWkfR4doazY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=acLlAvE3LKJCxRngty8liaw8Qk236gx4kKT57lBEA1SRfjNdKNCxdPrOPF7R1IfIH KPaAz8tgSfKrIkGvIPYKu+zhJ58wbjHq76TXvQOIHhGbh/kkAsOvNhwgmSMU8tVAPI 6BwGsPS5KusZQ4H+lfSfn/OLvDiXpY2ZGROEVl74= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cameron Gutman , Dmitry Torokhov , Sasha Levin Subject: [PATCH 4.9 51/92] Input: xpad - dont depend on endpoint order Date: Thu, 29 Nov 2018 15:12:20 +0100 Message-Id: <20181129140110.529408729@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140106.520639693@linuxfoundation.org> References: <20181129140106.520639693@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit c01b5e7464f0cf20936d7467c7528163c4e2782d ] The order of endpoints is well defined on official Xbox pads, but we have found at least one 3rd-party pad that doesn't follow the standard ("Titanfall 2 Xbox One controller" 0e6f:0165). Fortunately, we get lucky with this specific pad because it uses endpoint addresses that differ only by direction. We know that there are other pads out where this is not true, so let's go ahead and fix this. Signed-off-by: Cameron Gutman Signed-off-by: Dmitry Torokhov Signed-off-by: Sasha Levin --- drivers/input/joystick/xpad.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index d837900d609e..dd0503562b1c 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -838,10 +838,9 @@ static void xpad_irq_out(struct urb *urb) spin_unlock_irqrestore(&xpad->odata_lock, flags); } -static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) +static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad, + struct usb_endpoint_descriptor *ep_irq_out) { - struct usb_endpoint_descriptor *ep_irq_out; - int ep_irq_out_idx; int error; if (xpad->xtype == XTYPE_UNKNOWN) @@ -862,10 +861,6 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) goto err_free_coherent; } - /* Xbox One controller has in/out endpoints swapped. */ - ep_irq_out_idx = xpad->xtype == XTYPE_XBOXONE ? 0 : 1; - ep_irq_out = &intf->cur_altsetting->endpoint[ep_irq_out_idx].desc; - usb_fill_int_urb(xpad->irq_out, xpad->udev, usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress), xpad->odata, XPAD_PKT_LEN, @@ -1455,8 +1450,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id { struct usb_device *udev = interface_to_usbdev(intf); struct usb_xpad *xpad; - struct usb_endpoint_descriptor *ep_irq_in; - int ep_irq_in_idx; + struct usb_endpoint_descriptor *ep_irq_in, *ep_irq_out; int i, error; if (intf->cur_altsetting->desc.bNumEndpoints != 2) @@ -1526,13 +1520,26 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id goto err_free_in_urb; } - error = xpad_init_output(intf, xpad); - if (error) + ep_irq_in = ep_irq_out = NULL; + + for (i = 0; i < 2; i++) { + struct usb_endpoint_descriptor *ep = + &intf->cur_altsetting->endpoint[i].desc; + + if (usb_endpoint_dir_in(ep)) + ep_irq_in = ep; + else + ep_irq_out = ep; + } + + if (!ep_irq_in || !ep_irq_out) { + error = -ENODEV; goto err_free_in_urb; + } - /* Xbox One controller has in/out endpoints swapped. */ - ep_irq_in_idx = xpad->xtype == XTYPE_XBOXONE ? 1 : 0; - ep_irq_in = &intf->cur_altsetting->endpoint[ep_irq_in_idx].desc; + error = xpad_init_output(intf, xpad, ep_irq_out); + if (error) + goto err_free_in_urb; usb_fill_int_urb(xpad->irq_in, udev, usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), -- 2.17.1