Author: vmikayelyan
Date: Fri Aug 19 16:27:37 2016
New Revision: 72381
URL:
http://svn.reactos.org/svn/reactos?rev=72381&view=rev
Log:
usb: hub: FDO: Fix USBHUB_FdoStartDevice()
Done fixes in cleanup also refactored code to be more readable and error
safe.
Modified:
branches/GSoC_2016/USB/drivers/usb/usbhub/fdo.c
Modified: branches/GSoC_2016/USB/drivers/usb/usbhub/fdo.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/USB/drivers/usb/usbhu…
==============================================================================
--- branches/GSoC_2016/USB/drivers/usb/usbhub/fdo.c [iso-8859-1] (original)
+++ branches/GSoC_2016/USB/drivers/usb/usbhub/fdo.c [iso-8859-1] Fri Aug 19 16:27:37 2016
@@ -1581,7 +1581,8 @@
if (!Urb)
{
// no memory
- return STATUS_INSUFFICIENT_RESOURCES;
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto cleanup;
}
// zero urb
@@ -1596,8 +1597,7 @@
{
// failed to obtain hub pdo
DPRINT1("IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO failed with %x\n",
Status);
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
// sanity checks
@@ -1614,8 +1614,7 @@
{
// failed to start pdo
DPRINT1("Failed to start the RootHub PDO\n");
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
// Get the current number of hubs
@@ -1626,8 +1625,7 @@
{
// failed to get number of hubs
DPRINT1("IOCTL_INTERNAL_USB_GET_HUB_COUNT failed with %x\n", Status);
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
// Get the Hub Interface
@@ -1641,8 +1639,7 @@
{
// failed to get root hub interface
DPRINT1("Failed to get HUB_GUID interface with status 0x%08lx\n",
Status);
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
HubInterfaceBusContext = HubDeviceExtension->HubInterface.BusContext;
@@ -1658,8 +1655,7 @@
{
// failed to get usbdi interface
DPRINT1("Failed to get USBDI_GUID interface with status 0x%08lx\n",
Status);
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
// Get Root Hub Device Handle
@@ -1672,8 +1668,7 @@
{
// failed
DPRINT1("IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE failed with status
0x%08lx\n", Status);
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
//
@@ -1717,8 +1712,7 @@
{
// failed to get device descriptor of hub
DPRINT1("Failed to get HubDeviceDescriptor!\n");
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
// build configuration request
@@ -1745,8 +1739,7 @@
{
// failed to get configuration descriptor
DPRINT1("Failed to get RootHub Configuration with status %x\n",
Status);
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
// sanity checks
@@ -1772,16 +1765,15 @@
{
// failed to get hub information
DPRINT1("Failed to extended hub information. Unable to determine the number
of ports!\n");
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
if (!HubDeviceExtension->UsbExtHubInfo.NumberOfPorts)
{
// bogus port driver
DPRINT1("Failed to retrieve the number of ports\n");
- ExFreePool(Urb);
- return STATUS_UNSUCCESSFUL;
+ Status = STATUS_UNSUCCESSFUL;
+ goto cleanup;
}
DPRINT("HubDeviceExtension->UsbExtHubInfo.NumberOfPorts %x\n",
HubDeviceExtension->UsbExtHubInfo.NumberOfPorts);
@@ -1812,8 +1804,8 @@
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to get Hub Descriptor!\n");
- ExFreePool(Urb);
- return STATUS_UNSUCCESSFUL;
+ Status = STATUS_UNSUCCESSFUL;
+ goto cleanup;
}
// sanity checks
@@ -1841,14 +1833,21 @@
{
// failed to get hub status
DPRINT1("Failed to get Hub Status!\n");
- ExFreePool(Urb);
- return STATUS_UNSUCCESSFUL;
+ Status = STATUS_UNSUCCESSFUL;
+ goto cleanup;
}
// Allocate memory for PortStatusChange to hold 2 USHORTs for each port on hub
HubDeviceExtension->PortStatusChange = ExAllocatePoolWithTag(NonPagedPool,
sizeof(ULONG) *
HubDeviceExtension->UsbExtHubInfo.NumberOfPorts,
USB_HUB_TAG);
+
+ if (!HubDeviceExtension->PortStatusChange)
+ {
+ DPRINT1("Failed to allocate pool for PortStatusChange!\n");
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto cleanup;
+ }
// Get the first Configuration Descriptor
Pid =
USBD_ParseConfigurationDescriptorEx(&HubDeviceExtension->HubConfigDescriptor,
@@ -1858,8 +1857,8 @@
{
// failed parse hub descriptor
DPRINT1("Failed to parse configuration descriptor\n");
- ExFreePool(Urb);
- return STATUS_UNSUCCESSFUL;
+ Status = STATUS_UNSUCCESSFUL;
+ goto cleanup;
}
// create configuration request
@@ -1870,8 +1869,8 @@
{
// failed to build urb
DPRINT1("Failed to allocate urb\n");
- ExFreePool(Urb);
- return STATUS_INSUFFICIENT_RESOURCES;
+ Status = STATUS_INSUFFICIENT_RESOURCES;
+ goto cleanup;
}
// send request
@@ -1883,9 +1882,7 @@
{
// failed to select configuration
DPRINT1("Failed to select configuration with %x\n", Status);
- ExFreePool(Urb);
- ExFreePool(ConfigUrb);
- return Status;
+ goto cleanup;
}
// store configuration & pipe handle
@@ -1895,10 +1892,6 @@
FDO_QueryInterface(DeviceObject, &HubDeviceExtension->DeviceInterface);
-
- // free urb
- ExFreePool(ConfigUrb);
-
// check if function is available
if (HubDeviceExtension->UsbDInterface.IsDeviceHighSpeed)
{
@@ -1938,8 +1931,7 @@
if (!NT_SUCCESS(Status))
{
DPRINT1("Failed to set callback\n");
- ExFreePool(Urb);
- return Status;
+ goto cleanup;
}
}
else
@@ -1991,7 +1983,29 @@
// free urb
ExFreePool(Urb);
+ // free ConfigUrb
+ ExFreePool(ConfigUrb);
+
// done
+ return Status;
+
+cleanup:
+ if (Urb)
+ ExFreePool(Urb);
+
+ // Dereference interfaces
+ if (HubDeviceExtension->HubInterface.Size)
+
HubDeviceExtension->HubInterface.InterfaceDereference(HubDeviceExtension->HubInterface.BusContext);
+
+ if (HubDeviceExtension->UsbDInterface.Size)
+
HubDeviceExtension->UsbDInterface.InterfaceDereference(HubDeviceExtension->UsbDInterface.BusContext);
+
+ if (HubDeviceExtension->PortStatusChange)
+ ExFreePool(HubDeviceExtension->PortStatusChange);
+
+ if (ConfigUrb)
+ ExFreePool(ConfigUrb);
+
return Status;
}