linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hid: usbhid: Use flag HID_DISCONNECTED when a usb device is removed
@ 2014-07-25  5:13 Reyad Attiyat
  2014-07-25 19:06 ` Reyad Attiyat
  2014-07-29 11:06 ` Jiri Kosina
  0 siblings, 2 replies; 3+ messages in thread
From: Reyad Attiyat @ 2014-07-25  5:13 UTC (permalink / raw)
  To: linux-input, jkosina, srinivas.pandruvada, linux-kernel; +Cc: Reyad Attiyat

Set disconnected flag in struct usbhid when a usb device
is removed. Check for disconnected flag before sending urb
requests. This prevents a kernel panic when a hid driver calls
hid_hw_request() after removing a usb device.

Signed-off-by: Reyad Attiyat <reyad.attiyat@gmail.com>
---
 drivers/hid/usbhid/hid-core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 7b88f4c..c8fa957 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -536,7 +536,8 @@ static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *re
 	int head;
 	struct usbhid_device *usbhid = hid->driver_data;
 
-	if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
+	if (((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) ||
+		test_bit(HID_DISCONNECTED, &usbhid->iofl))
 		return;
 
 	if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) {
@@ -1366,6 +1367,9 @@ static void usbhid_disconnect(struct usb_interface *intf)
 		return;
 
 	usbhid = hid->driver_data;
+	spin_lock_irq(&usbhid->lock);	/* Sync with error and led handlers */
+	set_bit(HID_DISCONNECTED, &usbhid->iofl);
+	spin_unlock_irq(&usbhid->lock);
 	hid_destroy_device(hid);
 	kfree(usbhid);
 }
-- 
1.9.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] hid: usbhid: Use flag HID_DISCONNECTED when a usb device is removed
  2014-07-25  5:13 [PATCH] hid: usbhid: Use flag HID_DISCONNECTED when a usb device is removed Reyad Attiyat
@ 2014-07-25 19:06 ` Reyad Attiyat
  2014-07-29 11:06 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Reyad Attiyat @ 2014-07-25 19:06 UTC (permalink / raw)
  To: linux-input, Jiri Kosina, Srinivas Pandruvada, linux-kernel; +Cc: Reyad Attiyat

The kernel panic happened when the iio sensor hid usb device was
removed. It tries to set the power state by calling hid_hw_request().
This was on kernel 3.16-rc6
https://gist.github.com/soda0289/2ff543d9cfff6f92c360#file-kernel-panic-when-iio-sensor-usb-device-is-removed

On Fri, Jul 25, 2014 at 12:13 AM, Reyad Attiyat <reyad.attiyat@gmail.com> wrote:
> Set disconnected flag in struct usbhid when a usb device
> is removed. Check for disconnected flag before sending urb
> requests. This prevents a kernel panic when a hid driver calls
> hid_hw_request() after removing a usb device.
>
> Signed-off-by: Reyad Attiyat <reyad.attiyat@gmail.com>
> ---
>  drivers/hid/usbhid/hid-core.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
> index 7b88f4c..c8fa957 100644
> --- a/drivers/hid/usbhid/hid-core.c
> +++ b/drivers/hid/usbhid/hid-core.c
> @@ -536,7 +536,8 @@ static void __usbhid_submit_report(struct hid_device *hid, struct hid_report *re
>         int head;
>         struct usbhid_device *usbhid = hid->driver_data;
>
> -       if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
> +       if (((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) ||
> +               test_bit(HID_DISCONNECTED, &usbhid->iofl))
>                 return;
>
>         if (usbhid->urbout && dir == USB_DIR_OUT && report->type == HID_OUTPUT_REPORT) {
> @@ -1366,6 +1367,9 @@ static void usbhid_disconnect(struct usb_interface *intf)
>                 return;
>
>         usbhid = hid->driver_data;
> +       spin_lock_irq(&usbhid->lock);   /* Sync with error and led handlers */
> +       set_bit(HID_DISCONNECTED, &usbhid->iofl);
> +       spin_unlock_irq(&usbhid->lock);
>         hid_destroy_device(hid);
>         kfree(usbhid);
>  }
> --
> 1.9.3
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] hid: usbhid: Use flag HID_DISCONNECTED when a usb device is removed
  2014-07-25  5:13 [PATCH] hid: usbhid: Use flag HID_DISCONNECTED when a usb device is removed Reyad Attiyat
  2014-07-25 19:06 ` Reyad Attiyat
@ 2014-07-29 11:06 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2014-07-29 11:06 UTC (permalink / raw)
  To: Reyad Attiyat; +Cc: linux-input, srinivas.pandruvada, linux-kernel

On Fri, 25 Jul 2014, Reyad Attiyat wrote:

> Set disconnected flag in struct usbhid when a usb device
> is removed. Check for disconnected flag before sending urb
> requests. This prevents a kernel panic when a hid driver calls
> hid_hw_request() after removing a usb device.
> 
> Signed-off-by: Reyad Attiyat <reyad.attiyat@gmail.com>

I've included the full oops output into the changelog and applied, thanks.

-- 
Jiri Kosina
SUSE Labs

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-29 11:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-25  5:13 [PATCH] hid: usbhid: Use flag HID_DISCONNECTED when a usb device is removed Reyad Attiyat
2014-07-25 19:06 ` Reyad Attiyat
2014-07-29 11:06 ` Jiri Kosina

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).