linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Rojtberg <rojtberg@gmail.com>
To: linux-input@vger.kernel.org, pgriffais@valvesoftware.com,
	dmitry.torokhov@gmail.com, gregkh@linuxfoundation.org
Cc: Pavel Rojtberg <rojtberg@gmail.com>
Subject: [PATCH 11/15] Input: xpad: do not submit active URBs
Date: Thu,  1 Oct 2015 22:57:22 +0200	[thread overview]
Message-ID: <1443733046-29610-12-git-send-email-rojtberg@gmail.com> (raw)
In-Reply-To: <1443733046-29610-1-git-send-email-rojtberg@gmail.com>

From: Pavel Rojtberg <rojtberg@gmail.com>

track the active status of the irq_out URB to prevent submission while
it is active. Failure to do so results in the "URB submitted while
active" warning/ stacktrace.

Also add missing mutex locking around xpad->odata usages.

Signed-off-by: Pavel Rojtberg <rojtberg@gmail.com>
---
 drivers/input/joystick/xpad.c | 43 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 7d53e8e..5eec515 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -330,6 +330,7 @@ struct usb_xpad {
 	dma_addr_t idata_dma;
 
 	struct urb *irq_out;		/* urb for interrupt out report */
+	int irq_out_active;		/* we must not use an active URB */
 	unsigned char *odata;		/* output data */
 	dma_addr_t odata_dma;
 	struct mutex odata_mutex;
@@ -710,6 +711,7 @@ static void xpad_irq_out(struct urb *urb)
 	switch (status) {
 	case 0:
 		/* success */
+		xpad->irq_out_active = 0;
 		return;
 
 	case -ECONNRESET:
@@ -718,6 +720,7 @@ static void xpad_irq_out(struct urb *urb)
 		/* this urb is terminated, clean up */
 		dev_dbg(dev, "%s - urb shutting down with status: %d\n",
 			__func__, status);
+		xpad->irq_out_active = 0;
 		return;
 
 	default:
@@ -795,6 +798,7 @@ static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect
 	struct usb_xpad *xpad = input_get_drvdata(dev);
 	__u16 strong;
 	__u16 weak;
+	int retval;
 
 	if (effect->type != FF_RUMBLE)
 		return 0;
@@ -802,6 +806,8 @@ static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect
 	strong = effect->u.rumble.strong_magnitude;
 	weak = effect->u.rumble.weak_magnitude;
 
+	mutex_lock(&xpad->odata_mutex);
+
 	switch (xpad->xtype) {
 	case XTYPE_XBOX:
 		xpad->odata[0] = 0x00;
@@ -858,13 +864,25 @@ static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect
 		break;
 
 	default:
+		mutex_unlock(&xpad->odata_mutex);
 		dev_dbg(&xpad->dev->dev,
 			"%s - rumble command sent to unsupported xpad type: %d\n",
 			__func__, xpad->xtype);
 		return -EINVAL;
 	}
 
-	return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
+	if (!xpad->irq_out_active) {
+		retval = usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
+		xpad->irq_out_active = 1;
+	} else {
+		retval = -EIO;
+		dev_dbg(&xpad->dev->dev, "%s - dropped, irq_out is active\n",
+				__func__);
+	}
+
+	mutex_unlock(&xpad->odata_mutex);
+
+	return retval;
 }
 
 static int xpad_init_ff(struct usb_xpad *xpad)
@@ -940,7 +958,13 @@ static void xpad_send_led_command(struct usb_xpad *xpad, int command)
 		break;
 	}
 
-	usb_submit_urb(xpad->irq_out, GFP_KERNEL);
+	if (!xpad->irq_out_active) {
+		usb_submit_urb(xpad->irq_out, GFP_KERNEL);
+		xpad->irq_out_active = 1;
+	} else
+		dev_dbg(&xpad->dev->dev, "%s - dropped, irq_out is active\n",
+				__func__);
+
 	mutex_unlock(&xpad->odata_mutex);
 }
 
@@ -1028,6 +1052,7 @@ static void xpad_identify_controller(struct usb_xpad *xpad) { }
 static int xpad_open(struct input_dev *dev)
 {
 	struct usb_xpad *xpad = input_get_drvdata(dev);
+	int retval;
 
 	/* URB was submitted in probe */
 	if (xpad->xtype == XTYPE_XBOX360W)
@@ -1038,11 +1063,14 @@ static int xpad_open(struct input_dev *dev)
 		return -EIO;
 
 	if (xpad->xtype == XTYPE_XBOXONE) {
+		mutex_lock(&xpad->odata_mutex);
 		/* Xbox one controller needs to be initialized. */
 		xpad->odata[0] = 0x05;
 		xpad->odata[1] = 0x20;
 		xpad->irq_out->transfer_buffer_length = 2;
-		return usb_submit_urb(xpad->irq_out, GFP_KERNEL);
+		retval = usb_submit_urb(xpad->irq_out, GFP_KERNEL);
+		mutex_unlock(&xpad->odata_mutex);
+		return retval;
 	}
 
 	return 0;
@@ -1300,7 +1328,14 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
 		xpad->odata[10] = 0x00;
 		xpad->odata[11] = 0x00;
 		xpad->irq_out->transfer_buffer_length = 12;
-		usb_submit_urb(xpad->irq_out, GFP_KERNEL);
+
+		if (!xpad->irq_out_active) {
+			usb_submit_urb(xpad->irq_out, GFP_KERNEL);
+			xpad->irq_out_active = 1;
+		} else
+			dev_dbg(&xpad->dev->dev,
+				"%s - dropped, irq_out is active\n", __func__);
+
 		mutex_unlock(&xpad->odata_mutex);
 	} else {
 		xpad->pad_present = 1;
-- 
1.9.1


  parent reply	other threads:[~2015-10-01 20:57 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-01 20:57 [PATCH 00/15] Input: xpad: updates Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 01/15] Input: xpad: add Covert Forces edition of the Xbox One controller Pavel Rojtberg
2015-10-10 16:42   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 02/15] Input: xpad: fix Razer Atrox Arcade Stick button mapping Pavel Rojtberg
2015-10-10 16:43   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 03/15] Input: xpad: clarify LED enumeration Pavel Rojtberg
2015-10-10 16:44   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 04/15] Input: xpad: remove needless bulk out URB used for LED setup Pavel Rojtberg
2015-10-10 16:45   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 05/15] Input: xpad: factor out URB submission in xpad_play_effect Pavel Rojtberg
2015-10-10 16:45   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 06/15] Input: xpad: x360w: report dpad as buttons and axes Pavel Rojtberg
2015-10-10 16:45   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 07/15] Input: xpad: move the input device creation to a new function Pavel Rojtberg
2015-10-10 18:00   ` Dmitry Torokhov
2015-10-15 19:19     ` Pavel Rojtberg
2015-10-17 16:49       ` Dmitry Torokhov
2015-10-17 18:08         ` Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 08/15] Input: xpad: query Wireless controller state at init Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 09/15] Input: xpad: handle "present" and "gone" correctly Pavel Rojtberg
2015-10-10 16:42   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 10/15] Input: xpad: use ida() for finding the pad_nr Pavel Rojtberg
2015-10-01 22:53   ` Pavel Rojtberg
2015-10-10 17:06     ` Dmitry Torokhov
2015-10-01 20:57 ` Pavel Rojtberg [this message]
2015-10-01 20:57 ` [PATCH 12/15] Input: xpad: replace mutex by spinlock Pavel Rojtberg
2015-10-10 18:10   ` Dmitry Torokhov
2015-10-01 20:57 ` [PATCH 13/15] Input: xpad: re-submit pending ff and led requests Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 14/15] Input: xpad: workaround dead irq_out after suspend/ resume Pavel Rojtberg
2015-10-01 20:57 ` [PATCH 15/15] Input: xpad: update Xbox One Force Feedback Support Pavel Rojtberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443733046-29610-12-git-send-email-rojtberg@gmail.com \
    --to=rojtberg@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-input@vger.kernel.org \
    --cc=pgriffais@valvesoftware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).