@@ -1581,7 +1581,8 @@ USBHUB_FdoStartDevice(
1581
1581
if (!Urb )
1582
1582
{
1583
1583
// no memory
1584
- return STATUS_INSUFFICIENT_RESOURCES ;
1584
+ Status = STATUS_INSUFFICIENT_RESOURCES ;
1585
+ goto cleanup ;
1585
1586
}
1586
1587
1587
1588
// zero urb
@@ -1596,8 +1597,7 @@ USBHUB_FdoStartDevice(
1596
1597
{
1597
1598
// failed to obtain hub pdo
1598
1599
DPRINT1 ("IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO failed with %x\n" , Status );
1599
- ExFreePool (Urb );
1600
- return Status ;
1600
+ goto cleanup ;
1601
1601
}
1602
1602
1603
1603
// sanity checks
@@ -1614,8 +1614,7 @@ USBHUB_FdoStartDevice(
1614
1614
{
1615
1615
// failed to start pdo
1616
1616
DPRINT1 ("Failed to start the RootHub PDO\n" );
1617
- ExFreePool (Urb );
1618
- return Status ;
1617
+ goto cleanup ;
1619
1618
}
1620
1619
1621
1620
// Get the current number of hubs
@@ -1626,8 +1625,7 @@ USBHUB_FdoStartDevice(
1626
1625
{
1627
1626
// failed to get number of hubs
1628
1627
DPRINT1 ("IOCTL_INTERNAL_USB_GET_HUB_COUNT failed with %x\n" , Status );
1629
- ExFreePool (Urb );
1630
- return Status ;
1628
+ goto cleanup ;
1631
1629
}
1632
1630
1633
1631
// Get the Hub Interface
@@ -1641,8 +1639,7 @@ USBHUB_FdoStartDevice(
1641
1639
{
1642
1640
// failed to get root hub interface
1643
1641
DPRINT1 ("Failed to get HUB_GUID interface with status 0x%08lx\n" , Status );
1644
- ExFreePool (Urb );
1645
- return Status ;
1642
+ goto cleanup ;
1646
1643
}
1647
1644
1648
1645
HubInterfaceBusContext = HubDeviceExtension -> HubInterface .BusContext ;
@@ -1658,8 +1655,7 @@ USBHUB_FdoStartDevice(
1658
1655
{
1659
1656
// failed to get usbdi interface
1660
1657
DPRINT1 ("Failed to get USBDI_GUID interface with status 0x%08lx\n" , Status );
1661
- ExFreePool (Urb );
1662
- return Status ;
1658
+ goto cleanup ;
1663
1659
}
1664
1660
1665
1661
// Get Root Hub Device Handle
@@ -1672,8 +1668,7 @@ USBHUB_FdoStartDevice(
1672
1668
{
1673
1669
// failed
1674
1670
DPRINT1 ("IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE failed with status 0x%08lx\n" , Status );
1675
- ExFreePool (Urb );
1676
- return Status ;
1671
+ goto cleanup ;
1677
1672
}
1678
1673
1679
1674
//
@@ -1717,8 +1712,7 @@ USBHUB_FdoStartDevice(
1717
1712
{
1718
1713
// failed to get device descriptor of hub
1719
1714
DPRINT1 ("Failed to get HubDeviceDescriptor!\n" );
1720
- ExFreePool (Urb );
1721
- return Status ;
1715
+ goto cleanup ;
1722
1716
}
1723
1717
1724
1718
// build configuration request
@@ -1745,8 +1739,7 @@ USBHUB_FdoStartDevice(
1745
1739
{
1746
1740
// failed to get configuration descriptor
1747
1741
DPRINT1 ("Failed to get RootHub Configuration with status %x\n" , Status );
1748
- ExFreePool (Urb );
1749
- return Status ;
1742
+ goto cleanup ;
1750
1743
}
1751
1744
1752
1745
// sanity checks
@@ -1772,16 +1765,15 @@ USBHUB_FdoStartDevice(
1772
1765
{
1773
1766
// failed to get hub information
1774
1767
DPRINT1 ("Failed to extended hub information. Unable to determine the number of ports!\n" );
1775
- ExFreePool (Urb );
1776
- return Status ;
1768
+ goto cleanup ;
1777
1769
}
1778
1770
1779
1771
if (!HubDeviceExtension -> UsbExtHubInfo .NumberOfPorts )
1780
1772
{
1781
1773
// bogus port driver
1782
1774
DPRINT1 ("Failed to retrieve the number of ports\n" );
1783
- ExFreePool ( Urb ) ;
1784
- return STATUS_UNSUCCESSFUL ;
1775
+ Status = STATUS_UNSUCCESSFUL ;
1776
+ goto cleanup ;
1785
1777
}
1786
1778
1787
1779
DPRINT ("HubDeviceExtension->UsbExtHubInfo.NumberOfPorts %x\n" , HubDeviceExtension -> UsbExtHubInfo .NumberOfPorts );
@@ -1812,8 +1804,8 @@ USBHUB_FdoStartDevice(
1812
1804
if (!NT_SUCCESS (Status ))
1813
1805
{
1814
1806
DPRINT1 ("Failed to get Hub Descriptor!\n" );
1815
- ExFreePool ( Urb ) ;
1816
- return STATUS_UNSUCCESSFUL ;
1807
+ Status = STATUS_UNSUCCESSFUL ;
1808
+ goto cleanup ;
1817
1809
}
1818
1810
1819
1811
// sanity checks
@@ -1841,15 +1833,22 @@ USBHUB_FdoStartDevice(
1841
1833
{
1842
1834
// failed to get hub status
1843
1835
DPRINT1 ("Failed to get Hub Status!\n" );
1844
- ExFreePool ( Urb ) ;
1845
- return STATUS_UNSUCCESSFUL ;
1836
+ Status = STATUS_UNSUCCESSFUL ;
1837
+ goto cleanup ;
1846
1838
}
1847
1839
1848
1840
// Allocate memory for PortStatusChange to hold 2 USHORTs for each port on hub
1849
1841
HubDeviceExtension -> PortStatusChange = ExAllocatePoolWithTag (NonPagedPool ,
1850
1842
sizeof (ULONG ) * HubDeviceExtension -> UsbExtHubInfo .NumberOfPorts ,
1851
1843
USB_HUB_TAG );
1852
1844
1845
+ if (!HubDeviceExtension -> PortStatusChange )
1846
+ {
1847
+ DPRINT1 ("Failed to allocate pool for PortStatusChange!\n" );
1848
+ Status = STATUS_INSUFFICIENT_RESOURCES ;
1849
+ goto cleanup ;
1850
+ }
1851
+
1853
1852
// Get the first Configuration Descriptor
1854
1853
Pid = USBD_ParseConfigurationDescriptorEx (& HubDeviceExtension -> HubConfigDescriptor ,
1855
1854
& HubDeviceExtension -> HubConfigDescriptor ,
@@ -1858,8 +1857,8 @@ USBHUB_FdoStartDevice(
1858
1857
{
1859
1858
// failed parse hub descriptor
1860
1859
DPRINT1 ("Failed to parse configuration descriptor\n" );
1861
- ExFreePool ( Urb ) ;
1862
- return STATUS_UNSUCCESSFUL ;
1860
+ Status = STATUS_UNSUCCESSFUL ;
1861
+ goto cleanup ;
1863
1862
}
1864
1863
1865
1864
// create configuration request
@@ -1870,8 +1869,8 @@ USBHUB_FdoStartDevice(
1870
1869
{
1871
1870
// failed to build urb
1872
1871
DPRINT1 ("Failed to allocate urb\n" );
1873
- ExFreePool ( Urb ) ;
1874
- return STATUS_INSUFFICIENT_RESOURCES ;
1872
+ Status = STATUS_INSUFFICIENT_RESOURCES ;
1873
+ goto cleanup ;
1875
1874
}
1876
1875
1877
1876
// send request
@@ -1883,9 +1882,7 @@ USBHUB_FdoStartDevice(
1883
1882
{
1884
1883
// failed to select configuration
1885
1884
DPRINT1 ("Failed to select configuration with %x\n" , Status );
1886
- ExFreePool (Urb );
1887
- ExFreePool (ConfigUrb );
1888
- return Status ;
1885
+ goto cleanup ;
1889
1886
}
1890
1887
1891
1888
// store configuration & pipe handle
@@ -1895,10 +1892,6 @@ USBHUB_FdoStartDevice(
1895
1892
1896
1893
FDO_QueryInterface (DeviceObject , & HubDeviceExtension -> DeviceInterface );
1897
1894
1898
-
1899
- // free urb
1900
- ExFreePool (ConfigUrb );
1901
-
1902
1895
// check if function is available
1903
1896
if (HubDeviceExtension -> UsbDInterface .IsDeviceHighSpeed )
1904
1897
{
@@ -1938,8 +1931,7 @@ USBHUB_FdoStartDevice(
1938
1931
if (!NT_SUCCESS (Status ))
1939
1932
{
1940
1933
DPRINT1 ("Failed to set callback\n" );
1941
- ExFreePool (Urb );
1942
- return Status ;
1934
+ goto cleanup ;
1943
1935
}
1944
1936
}
1945
1937
else
@@ -1991,8 +1983,30 @@ USBHUB_FdoStartDevice(
1991
1983
// free urb
1992
1984
ExFreePool (Urb );
1993
1985
1986
+ // free ConfigUrb
1987
+ ExFreePool (ConfigUrb );
1988
+
1994
1989
// done
1995
1990
return Status ;
1991
+
1992
+ cleanup :
1993
+ if (Urb )
1994
+ ExFreePool (Urb );
1995
+
1996
+ // Dereference interfaces
1997
+ if (HubDeviceExtension -> HubInterface .Size )
1998
+ HubDeviceExtension -> HubInterface .InterfaceDereference (HubDeviceExtension -> HubInterface .BusContext );
1999
+
2000
+ if (HubDeviceExtension -> UsbDInterface .Size )
2001
+ HubDeviceExtension -> UsbDInterface .InterfaceDereference (HubDeviceExtension -> UsbDInterface .BusContext );
2002
+
2003
+ if (HubDeviceExtension -> PortStatusChange )
2004
+ ExFreePool (HubDeviceExtension -> PortStatusChange );
2005
+
2006
+ if (ConfigUrb )
2007
+ ExFreePool (ConfigUrb );
2008
+
2009
+ return Status ;
1996
2010
}
1997
2011
1998
2012
NTSTATUS
0 commit comments