Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2497703imm; Mon, 24 Sep 2018 05:29:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaNJ3yIlTFdE7jOHXFzwP/lMplaAgIriIUe0L3fIO+i+BU5EdtGyhnet6GdP0IrQDCKr4BS X-Received: by 2002:a62:1655:: with SMTP id 82-v6mr4968431pfw.11.1537792180082; Mon, 24 Sep 2018 05:29:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792180; cv=none; d=google.com; s=arc-20160816; b=uoh2MKinpQcVSTWX7icgsTuvD7rWRXboIKF65JHv4cwF00BVtx5XRySNqfucXAlfjZ tt7XYwgsdkdBJYoSyGUYjTpfpOw8H9CYfDj0lvCHjZsVZv0djLCfj0ZcqD37zTlKxGjy t5FH4HACaqp/l6j+WNyy0h5NB1drQ/j5O70l8pRKhvRgiMETL+WY7Y622+Mbeyk53ueN I0UN3T9GCvtuGHg+aNhU1KBbIQMx4/j3WKy6PoWeDpFIM5mCy/AC8X6l95hkzWWsjBA7 7itr0OV+J5DNmE8KaS+cFD/1LvOFQ5ywAeQRHRk9aBRbLN6AHUd2xgP7MpnS/0lfllDN pNKw== 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; bh=H5ooDXgDo2uZF3MlbdYgbWBu76Yswl/KI3rG2zJhXKY=; b=pElQbdO/efcDP2PTcaOw7jpF6GFf2ZlXh0EjoEDRAiNBRg1Zx3QpRacY0aioZC7iYX UOJM3vY3zpk2CTLbw7POtjKHHYK6ZzkPv//RB9VBI65lYhuOmjuQ06t9uE0trzPIRLXL AYu47mmCxaGjVzPeU7yTrfnO37HLuVtBfd1odli49s4Dxy+2Kjx6GbFyVZMnaCwzJZ0R EFMetnAj0bvtnKi4oKewZ+zajqZEV/9a7+FhVSSryRcgjFPysg0ssrQFXj36+3bWA6OD s4YKCA1tSBf1x2OVZGFHI0HrUq32nUYyJOyUOKvtt1SA2xIo/B1sY9rgzvuQQBfptTLZ xoeg== 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 j9-v6si1543176plt.442.2018.09.24.05.29.24; Mon, 24 Sep 2018 05:29:40 -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 S1733021AbeIXSaU (ORCPT + 99 others); Mon, 24 Sep 2018 14:30:20 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57442 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730974AbeIXSaT (ORCPT ); Mon, 24 Sep 2018 14:30:19 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 049BD1018; Mon, 24 Sep 2018 12:28:24 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marcus Folkesson , Dmitry Torokhov , Sasha Levin Subject: [PATCH 4.18 031/235] Input: pxrc - fix freeing URB on device teardown Date: Mon, 24 Sep 2018 13:50:17 +0200 Message-Id: <20180924113108.000942164@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Torokhov [ Upstream commit 34dad2cf1104869ce2db2bddb34f8e6780c2ddaa ] URB is the only resource that is not managed, and thus is destroyed too early, before we unregister input device and stop URB in pxrc_close(). To fix it let's install custom devm handler to free the URB at the right time in devm unwind sequence. Reviewed-by: Marcus Folkesson Tested-by: Marcus Folkesson Signed-off-by: Dmitry Torokhov Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/input/joystick/pxrc.c | 68 +++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 37 deletions(-) --- a/drivers/input/joystick/pxrc.c +++ b/drivers/input/joystick/pxrc.c @@ -120,48 +120,51 @@ static void pxrc_close(struct input_dev mutex_unlock(&pxrc->pm_mutex); } +static void pxrc_free_urb(void *_pxrc) +{ + struct pxrc *pxrc = _pxrc; + + usb_free_urb(pxrc->urb); +} + static int pxrc_usb_init(struct pxrc *pxrc) { struct usb_endpoint_descriptor *epirq; unsigned int pipe; - int retval; + int error; /* Set up the endpoint information */ /* This device only has an interrupt endpoint */ - retval = usb_find_common_endpoints(pxrc->intf->cur_altsetting, - NULL, NULL, &epirq, NULL); - if (retval) { - dev_err(&pxrc->intf->dev, - "Could not find endpoint\n"); - goto error; + error = usb_find_common_endpoints(pxrc->intf->cur_altsetting, + NULL, NULL, &epirq, NULL); + if (error) { + dev_err(&pxrc->intf->dev, "Could not find endpoint\n"); + return error; } pxrc->bsize = usb_endpoint_maxp(epirq); pxrc->epaddr = epirq->bEndpointAddress; pxrc->data = devm_kmalloc(&pxrc->intf->dev, pxrc->bsize, GFP_KERNEL); - if (!pxrc->data) { - retval = -ENOMEM; - goto error; - } + if (!pxrc->data) + return -ENOMEM; usb_set_intfdata(pxrc->intf, pxrc); usb_make_path(pxrc->udev, pxrc->phys, sizeof(pxrc->phys)); strlcat(pxrc->phys, "/input0", sizeof(pxrc->phys)); pxrc->urb = usb_alloc_urb(0, GFP_KERNEL); - if (!pxrc->urb) { - retval = -ENOMEM; - goto error; - } + if (!pxrc->urb) + return -ENOMEM; + + error = devm_add_action_or_reset(&pxrc->intf->dev, pxrc_free_urb, pxrc); + if (error) + return error; pipe = usb_rcvintpipe(pxrc->udev, pxrc->epaddr), usb_fill_int_urb(pxrc->urb, pxrc->udev, pipe, pxrc->data, pxrc->bsize, pxrc_usb_irq, pxrc, 1); -error: - return retval; - - + return 0; } static int pxrc_input_init(struct pxrc *pxrc) @@ -197,7 +200,7 @@ static int pxrc_probe(struct usb_interfa const struct usb_device_id *id) { struct pxrc *pxrc; - int retval; + int error; pxrc = devm_kzalloc(&intf->dev, sizeof(*pxrc), GFP_KERNEL); if (!pxrc) @@ -207,29 +210,20 @@ static int pxrc_probe(struct usb_interfa pxrc->udev = usb_get_dev(interface_to_usbdev(intf)); pxrc->intf = intf; - retval = pxrc_usb_init(pxrc); - if (retval) - goto error; - - retval = pxrc_input_init(pxrc); - if (retval) - goto err_free_urb; + error = pxrc_usb_init(pxrc); + if (error) + return error; + + error = pxrc_input_init(pxrc); + if (error) + return error; return 0; - -err_free_urb: - usb_free_urb(pxrc->urb); - -error: - return retval; } static void pxrc_disconnect(struct usb_interface *intf) { - struct pxrc *pxrc = usb_get_intfdata(intf); - - usb_free_urb(pxrc->urb); - usb_set_intfdata(intf, NULL); + /* All driver resources are devm-managed. */ } static int pxrc_suspend(struct usb_interface *intf, pm_message_t message)