Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2578326imu; Thu, 29 Nov 2018 07:09:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/VWj9SECZQGggL10j5THVBZ2m7FN+Gr9z7dvdrM/LPuFg7yxVsw7TKE5Pp4tSoiIMC2LZqr X-Received: by 2002:a17:902:8bc6:: with SMTP id r6mr1817969plo.67.1543504169396; Thu, 29 Nov 2018 07:09:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543504169; cv=none; d=google.com; s=arc-20160816; b=xAYh9hp3Ny+meBxz30pZ2NsyLuLXdC3E7ug4xiONWRObCW0B5EIde1dq8h9o2fUxxZ 4KRJSwdh2NEpkU9uYyXA8DQwsi/7EYDtxW4szYxqW7AS82vXljSBhXK1bwD0jaSZiuCr JI0NPd6v8AZtskniz0pNJXjMXUXTKGtIOoI4aHDYSq9Ew60PJO0IW2VmpcYPJ0AeRpJ9 /wIVfkL110Zrp5asCe0tpG742i4cZmaXm2Go6FNS4Lx9tk2BySaM3g6nt06pDfy8QYdK JNIkrfcOSTarLflGJZPzCcHrb2srQ/vgtPJiwbjBLz/Na+m25Lch0B2s21XrX6AeNMnP t1aw== 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=zWECsusvnaJgGSt2JoQ/5hjTjQxxl02KnZvXWf7VhKU=; b=EAUdFRSZexA9IQ9N1/98Ui86iAClsunTCd7hffAozZ0SaixFFkNlF72SkjoXJB9RDU kcMb3X5VhmHbEkvBsvmWUeVFld/wPpwa/gDFwl21lwIV7iBR+u4jXpyGm1ok2qEXHKW9 rucFmdAgli4hxeFNNN5g4Yo8UEH2XWZ/YJR10z/NalxGkzsctgGBmNidtFWS6xebE5Yt Mjob1CFg2N4R43+4uAyUDd5obzliiU0Esood/XjMH/WThAFlzTTxw+otpQZEb8WF/hbK 0hvdA0zC0KyxALkfVtNtNytp8d4iQ/okEox2Mt/JSCzusmdivtkRexHHRerdMGyFNQBS xNRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0hJPFFXX; 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 gn8si2315676plb.264.2018.11.29.07.09.02; Thu, 29 Nov 2018 07:09:29 -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=0hJPFFXX; 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 S1729640AbeK3BVC (ORCPT + 99 others); Thu, 29 Nov 2018 20:21:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:42156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728241AbeK3BVB (ORCPT ); Thu, 29 Nov 2018 20:21:01 -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 3E04B205C9; Thu, 29 Nov 2018 14:15:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543500930; bh=DR/K80gUT/ha0w1DSzyTSNkG0yqzFzo4ltVAe2PrMdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0hJPFFXXM+cP9ihDMr6hx/XyYoczRsOfv5yyeyfR0k7IUKfzIIVxboLaHLeD95pm+ JJAwY5vQtZrcCTxpCRUOf6rZMY45xy+KK9pvt5C3H/b5PTPQAKJbDgPS10GpVBlkoa 5XhXDxifqpd2ChpWx+fz+WmO5kfjhGJNfvnEpK2o= 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 3.18 56/83] Input: xpad - dont depend on endpoint order Date: Thu, 29 Nov 2018 15:12:14 +0100 Message-Id: <20181129140140.811255450@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129140138.002176596@linuxfoundation.org> References: <20181129140138.002176596@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 3.18-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