Author: tfaber
Date: Sun May 12 19:03:02 2013
New Revision: 59012
URL:
http://svn.reactos.org/svn/reactos?rev=59012&view=rev
Log:
[HIDUSB]
- Unconfigure device, and don't leak memory
... okay, enough HID for now.
Modified:
trunk/reactos/drivers/hid/hidusb/hidusb.c
Modified: trunk/reactos/drivers/hid/hidusb/hidusb.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/hid/hidusb/hidusb.…
==============================================================================
--- trunk/reactos/drivers/hid/hidusb/hidusb.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/hid/hidusb/hidusb.c [iso-8859-1] Sun May 12 19:03:02 2013
@@ -1287,6 +1287,90 @@
}
NTSTATUS
+Hid_DisableConfiguration(
+ IN PDEVICE_OBJECT DeviceObject)
+{
+ PHID_DEVICE_EXTENSION DeviceExtension;
+ PHID_USB_DEVICE_EXTENSION HidDeviceExtension;
+ NTSTATUS Status;
+ PURB Urb;
+
+ //
+ // get device extension
+ //
+ DeviceExtension = DeviceObject->DeviceExtension;
+ HidDeviceExtension = DeviceExtension->MiniDeviceExtension;
+
+ //
+ // build urb
+ //
+ Urb = ExAllocatePoolWithTag(NonPagedPool,
+ sizeof(struct _URB_SELECT_CONFIGURATION),
+ HIDUSB_URB_TAG);
+ if (!Urb)
+ {
+ //
+ // no memory
+ //
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ //
+ // format urb
+ //
+ UsbBuildSelectConfigurationRequest(Urb,
+ sizeof(struct _URB_SELECT_CONFIGURATION),
+ NULL);
+
+ //
+ // dispatch request
+ //
+ Status = Hid_DispatchUrb(DeviceObject, Urb);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("[HIDUSB] Dispatching unconfigure URB failed with %lx\n",
Status);
+ }
+ else if (!USBD_SUCCESS(Urb->UrbHeader.Status))
+ {
+ DPRINT("[HIDUSB] Unconfigure URB failed with %lx\n", Status);
+ }
+
+ //
+ // free urb
+ //
+ ExFreePoolWithTag(Urb, HIDUSB_URB_TAG);
+
+ //
+ // free resources
+ //
+ HidDeviceExtension->ConfigurationHandle = NULL;
+
+ if (HidDeviceExtension->InterfaceInfo)
+ {
+ ExFreePoolWithTag(HidDeviceExtension->InterfaceInfo, HIDUSB_TAG);
+ HidDeviceExtension->InterfaceInfo = NULL;
+ }
+
+ if (HidDeviceExtension->ConfigurationDescriptor)
+ {
+ ExFreePoolWithTag(HidDeviceExtension->ConfigurationDescriptor, HIDUSB_TAG);
+ HidDeviceExtension->ConfigurationDescriptor = NULL;
+ HidDeviceExtension->HidDescriptor = NULL;
+ }
+
+ if (HidDeviceExtension->DeviceDescriptor)
+ {
+ ExFreePoolWithTag(HidDeviceExtension->DeviceDescriptor, HIDUSB_TAG);
+ HidDeviceExtension->DeviceDescriptor = NULL;
+ }
+
+ //
+ // done
+ //
+ return Status;
+}
+
+NTSTATUS
Hid_SetIdle(
IN PDEVICE_OBJECT DeviceObject)
{
@@ -1646,20 +1730,18 @@
case IRP_MN_REMOVE_DEVICE:
{
//
+ // unconfigure device
+ // FIXME: Call this on IRP_MN_SURPRISE_REMOVAL, but don't send URBs
+ // FIXME: Don't call this after we've already seen a surprise removal
or stop
+ //
+ Hid_DisableConfiguration(DeviceObject);
+
+ //
// pass request onto lower driver
//
IoSkipCurrentIrpStackLocation(Irp);
Status = IoCallDriver(DeviceExtension->NextDeviceObject, Irp);
- //
- // free resources
- //
- if (HidDeviceExtension->ConfigurationDescriptor)
- {
- ExFreePoolWithTag(HidDeviceExtension->ConfigurationDescriptor,
HIDUSB_TAG);
- HidDeviceExtension->ConfigurationDescriptor = NULL;
- }
-
return Status;
}
case IRP_MN_QUERY_PNP_DEVICE_STATE:
@@ -1702,8 +1784,9 @@
case IRP_MN_STOP_DEVICE:
{
//
- // FIXME: unconfigure the device
- //
+ // unconfigure device
+ //
+ Hid_DisableConfiguration(DeviceObject);
//
// prepare irp