Disconnect hidraw device when an input device is disconnected
Subsystems (4)
PATCH 1/1 Disconnect hidraw device when an input device is disconnected
Quoted 1 line
From
487bccfd500d161dadf7b92be1ca2f8cca2b7781Mon Sep 17 00:00:00 2001
From: Brian Rogers <[email protected]>
Date: Sun, 19 Jul 2009 18:23:21 -0700
Subject: [PATCH 2/2] Bluetooth: Disconnect hidraw device when an input device is disconnected
hidraw didn't exist when Bluetooth code was adapted to use the HID subsystem. Now that it does exist, hidp is responsible for disconnecting it. Without doing this, old hidraw devices stick around forever.
--- net/bluetooth/hidp/core.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
net/bluetooth/hidp/core.c +3 -0
@@ -40,6 +40,7 @@#include <linux/input.h> #include <linux/hid.h> +#include <linux/hidraw.h> #include <net/bluetooth/bluetooth.h> #include <net/bluetooth/hci_core.h>
@@ -574,6 +575,8 @@ static int hidp_session(void *arg)if (session->hid) {if (session->hid->claimed &HID_CLAIMED_INPUT )hidinput_disconnect (session->hid); +if (session->hid->claimed &HID_CONNECT_HIDRAW ) +hidraw_disconnect (session->hid);hid_destroy_device (session->hid); }
Signature · 1 line
1.6.3.3
Marcel Holtmann
maintainerHi Brian,
Quoted 24 lines
hidraw didn't exist when Bluetooth code was adapted to use the HID subsystem.
Now that it does exist, hidp is responsible for disconnecting it. Without
doing this, old hidraw devices stick around forever.Signed-off-by Brian Rogers <[email protected]>--- net/bluetooth/hidp/core.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)net/bluetooth/hidp/core.c +1
-0@@ -40,6 +40,7 @@#include <linux/input.h> #include <linux/hid.h> +#include <linux/hidraw.h> #include <net/bluetooth/bluetooth.h> #include <net/bluetooth/hci_core.h>
net/bluetooth/hidp/core.c static int hidp_session(void *arg) · line 581
Quoted 7 lines
net/bluetooth/hidp/core.c +2
-0@@ -574,6 +575,8 @@ static int hidp_session(void *arg)if (session->hid) {if (session->hid->claimed &HID_CLAIMED_INPUT )hidinput_disconnect (session->hid); +if (session->hid->claimed &HID_CONNECT_HIDRAW ) +hidraw_disconnect (session->hid);hid_destroy_device (session->hid); }
patch looks good. However I don't understand why the HID core can't do that for us. This seems wrong for both cases.
Jiri, why does the HID core register input device and HIDRAW device for us, but not disconnect it?
Regards
Marcel
Quoted 20 lines · Marcel Holtmann
Quoted 20 lines
hidraw didn't exist when Bluetooth code was adapted to use the HID subsystem. Now that it does exist, hidp is responsible for disconnecting it. Without doing this, old hidraw devices stick around forever.
Signed-off-by Brian Rogers <[email protected]>--- net/bluetooth/hidp/core.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)net/bluetooth/hidp/core.c +1
-0@@ -40,6 +40,7 @@#include <linux/input.h> #include <linux/hid.h> +#include <linux/hidraw.h>
Quoted 7 lines
net/bluetooth/hidp/core.c static int hidp_session(void *arg) · line 578
Quoted 7 lines
net/bluetooth/hidp/core.c +1
-0#include <net/bluetooth/bluetooth.h> #include <net/bluetooth/hci_core.h> @@ -574,6 +575,8 @@ static int hidp_session(void *arg)if (session->hid) {if (session->hid->claimed &HID_CLAIMED_INPUT )hidinput_disconnect (session->hid); +if (session->hid->claimed &HID_CONNECT_HIDRAW )
This should rather be HID_CLAIMED_HIDRAW.
Quoted 9 lines
net/bluetooth/hidp/core.c static int hidp_session(void *arg) · line 581
Quoted 3 lines
net/bluetooth/hidp/core.c +1
-0+hidraw_disconnect (session->hid);hid_destroy_device (session->hid); }patch looks good. However I don't understand why the HID core can't do that for us. This seems wrong for both cases.
Jiri, why does the HID core register input device and HIDRAW device for us, but not disconnect it?
Yes, it indeed seems bogus. How about the patch below instead?
From: Jiri Kosina <[email protected]>
Subject: HID: consolidate connect and disconnect into core code
HID core registers input, hidraw and hiddev devices, but leaves unregistering it up to the individual driver, which is not really nice. Let's move all the logic to the core.
drivers/hid/hid-core.c +11 -0
@@ -1218,6 +1218,17 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) }EXPORT_SYMBOL_GPL (hid_connect); +void hid_disconnect (struct hid_device *hdev) +{ +if (hdev->claimed &HID_CLAIMED_INPUT ) +hidinput_disconnect (hdev); +if (hdev->claimed &HID_CLAIMED_HIDDEV ) + hdev->hiddev_disconnect (hdev); +if (hdev->claimed &HID_CLAIMED_HIDRAW ) +hidraw_disconnect (hdev); +} +EXPORT_SYMBOL_GPL (hid_disconnect); +/* a list of devices for which there is a specialized driver on HID bus */ static const struct hid_device_id hid_blacklist[] = { {HID_USB_DEVICE (USB_VENDOR_ID_A4TECH ,USB_DEVICE_ID_A4TECH_WCP32PU ) },
drivers/hid/usbhid/hid-core.c +5 -11
@@ -1047,13 +1047,6 @@ static void usbhid_stop(struct hid_device *hid)hid_cancel_delayed_stuff (usbhid); -if (hid->claimed &HID_CLAIMED_INPUT ) -hidinput_disconnect (hid); -if (hid->claimed &HID_CLAIMED_HIDDEV ) -hiddev_disconnect (hid); -if (hid->claimed &HID_CLAIMED_HIDRAW ) -hidraw_disconnect (hid); - hid->claimed =0 ;usb_free_urb (usbhid->urbin);
@@ -1091,7 +1084,7 @@ static struct hid_ll_driver usb_hid_driver = { .hidinput_input_event = usb_hidinput_input_event, }; -static int hid_probe (struct usb_interface *intf,const struct usb_device_id *id) +static int usbhid_probe (struct usb_interface *intf,const struct usb_device_id *id) {struct usb_host_interface *interface = intf->cur_altsetting;struct usb_device *dev =interface_to_usbdev (intf);
@@ -1123,6 +1116,7 @@ static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id) hid->ff_init = hid_pidff_init;#ifdef CONFIG_USB_HIDDEV hid->hiddev_connect = hiddev_connect; + hid->hiddev_disconnect = hiddev_disconnect; hid->hiddev_hid_event = hiddev_hid_event; hid->hiddev_report_event = hiddev_report_event;#endif
@@ -1183,7 +1177,7 @@ err:return ret; } -static void hid_disconnect (struct usb_interface *intf) +static void usbhid_disconnect (struct usb_interface *intf) {struct hid_device *hid =usb_get_intfdata (intf);struct usbhid_device *usbhid;
@@ -1365,8 +1359,8 @@ MODULE_DEVICE_TABLE (usb, hid_usb_ids);static struct usb_driver hid_driver = { .name ="usbhid" , - .probe = hid_probe, - .disconnect = hid_disconnect, + .probe = usbhid_probe, + .disconnect = usbhid_disconnect, #ifdef CONFIG_PM .suspend = hid_suspend, .resume = hid_resume,
include/linux/hid.h +3 -0
@@ -494,6 +494,7 @@ struct hid_device { /* device report descriptor *//* hiddev event handler */ int (*hiddev_connect)(struct hid_device *,unsigned int ); +void (*hiddev_disconnect)(struct hid_device *);void (*hiddev_hid_event) (struct hid_device *,struct hid_field *field,struct hid_usage *,__s32 );void (*hiddev_report_event) (struct hid_device *,struct hid_report *);
@@ -685,6 +686,7 @@ struct hid_device *hid_allocate_device(void);int hid_parse_report (struct hid_device *hid,__u8 *start,unsigned size);int hid_check_keys_pressed (struct hid_device *hid);int hid_connect (struct hid_device *hid,unsigned int connect_mask); +void hid_disconnect (struct hid_device *hid);/** * hid_map_usage - map usage input bits
@@ -794,6 +796,7 @@ static inline int __must_check hid_hw_start(struct hid_device *hdev,*/ static inline void hid_hw_stop (struct hid_device *hdev) { +hid_disconnect (hdev); hdev->ll_driver->stop (hdev); }
net/bluetooth/hidp/core.c +1 -6
@@ -570,11 +570,8 @@ static int hidp_session(void *arg) session->input =NULL ; } -if (session->hid) { -if (session->hid->claimed &HID_CLAIMED_INPUT ) -hidinput_disconnect (session->hid); +if (session->hid)hid_destroy_device (session->hid); - }/* Wakeup user-space polling for socket errors */ session->intr_sock->sk->sk_err =EUNATCH ;
@@ -729,8 +726,6 @@ static void hidp_stop(struct hid_device *hid)skb_queue_purge (&session->ctrl_transmit);skb_queue_purge (&session->intr_transmit); -if (hid->claimed &HID_CLAIMED_INPUT ) -hidinput_disconnect (hid); hid->claimed =0 ; }