@@ -1094,6 +1094,7 @@ DestroyUsbChildDeviceObject(
1094
1094
PDEVICE_OBJECT ChildDeviceObject = NULL ;
1095
1095
ULONG Index = 0 ;
1096
1096
1097
+ KeAcquireGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1097
1098
for (Index = 0 ; Index < USB_MAXCHILDREN ; Index ++ )
1098
1099
{
1099
1100
if (HubDeviceExtension -> ChildDeviceObject [Index ])
@@ -1114,15 +1115,17 @@ DestroyUsbChildDeviceObject(
1114
1115
if (!ChildDeviceObject )
1115
1116
{
1116
1117
DPRINT1 ("Removal request for non-existant device!\n" );
1118
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1117
1119
return STATUS_UNSUCCESSFUL ;
1118
1120
}
1119
1121
1120
1122
DPRINT ("Removing device on port %d (Child index: %d)\n" , PortId , Index );
1121
1123
1122
1124
/* Remove the device from the table */
1123
- // is lock needed?
1124
1125
HubDeviceExtension -> ChildDeviceObject [Index ] = NULL ;
1125
1126
1127
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1128
+
1126
1129
/* Invalidate device relations for the root hub */
1127
1130
IoInvalidateDeviceRelations (HubDeviceExtension -> RootHubPhysicalDeviceObject , BusRelations );
1128
1131
@@ -1153,26 +1156,6 @@ CreateUsbChildDeviceObject(
1153
1156
HubInterface = & HubDeviceExtension -> HubInterface ;
1154
1157
RootHubDeviceObject = HubDeviceExtension -> RootHubPhysicalDeviceObject ;
1155
1158
HubInterfaceBusContext = HubDeviceExtension -> UsbDInterface .BusContext ;
1156
- //
1157
- // Find an empty slot in the child device array
1158
- //
1159
- for (ChildDeviceCount = 0 ; ChildDeviceCount < USB_MAXCHILDREN ; ChildDeviceCount ++ )
1160
- {
1161
- if (HubDeviceExtension -> ChildDeviceObject [ChildDeviceCount ] == NULL )
1162
- {
1163
- DPRINT ("Found unused entry at %d\n" , ChildDeviceCount );
1164
- break ;
1165
- }
1166
- }
1167
-
1168
- //
1169
- // Check if the limit has been reached for maximum usb devices
1170
- //
1171
- if (ChildDeviceCount == USB_MAXCHILDREN )
1172
- {
1173
- DPRINT1 ("USBHUB: Too many child devices!\n" );
1174
- return STATUS_UNSUCCESSFUL ;
1175
- }
1176
1159
1177
1160
while (TRUE)
1178
1161
{
@@ -1341,8 +1324,35 @@ CreateUsbChildDeviceObject(
1341
1324
1342
1325
UsbChildExtension -> IsRemovePending = FALSE;
1343
1326
1327
+ KeAcquireGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1328
+
1329
+ //
1330
+ // Find an empty slot in the child device array
1331
+ //
1332
+ for (ChildDeviceCount = 0 ; ChildDeviceCount < USB_MAXCHILDREN ; ChildDeviceCount ++ )
1333
+ {
1334
+ if (HubDeviceExtension -> ChildDeviceObject [ChildDeviceCount ] == NULL )
1335
+ {
1336
+ DPRINT ("Found unused entry at %d\n" , ChildDeviceCount );
1337
+ break ;
1338
+ }
1339
+ }
1340
+
1341
+ //
1342
+ // Check if the limit has been reached for maximum usb devices
1343
+ //
1344
+ if (ChildDeviceCount == USB_MAXCHILDREN )
1345
+ {
1346
+ DPRINT1 ("USBHUB: Too many child devices!\n" );
1347
+ Status = STATUS_UNSUCCESSFUL ;
1348
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1349
+ UsbChildExtension -> DeviceInterface .InterfaceDereference (UsbChildExtension -> DeviceInterface .BusContext );
1350
+ goto Cleanup ;
1351
+ }
1352
+
1344
1353
HubDeviceExtension -> ChildDeviceObject [ChildDeviceCount ] = NewChildDeviceObject ;
1345
1354
HubDeviceExtension -> InstanceCount ++ ;
1355
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1346
1356
1347
1357
IoInvalidateDeviceRelations (RootHubDeviceObject , BusRelations );
1348
1358
return STATUS_SUCCESS ;
@@ -1398,6 +1408,8 @@ USBHUB_FdoQueryBusRelations(
1398
1408
1399
1409
HubDeviceExtension = (PHUB_DEVICE_EXTENSION )DeviceObject -> DeviceExtension ;
1400
1410
1411
+ KeAcquireGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1412
+
1401
1413
//
1402
1414
// Count the number of children
1403
1415
//
@@ -1418,6 +1430,7 @@ USBHUB_FdoQueryBusRelations(
1418
1430
{
1419
1431
// We have nothing to add
1420
1432
* pDeviceRelations = RelationsFromTop ;
1433
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1421
1434
return STATUS_SUCCESS ;
1422
1435
}
1423
1436
}
@@ -1432,6 +1445,7 @@ USBHUB_FdoQueryBusRelations(
1432
1445
1433
1446
if (!DeviceRelations )
1434
1447
{
1448
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1435
1449
if (!RelationsFromTop )
1436
1450
return STATUS_INSUFFICIENT_RESOURCES ;
1437
1451
else
@@ -1461,6 +1475,8 @@ USBHUB_FdoQueryBusRelations(
1461
1475
}
1462
1476
}
1463
1477
1478
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
1479
+
1464
1480
// We should do this, because replaced this with our's one
1465
1481
if (RelationsFromTop )
1466
1482
ExFreePool (RelationsFromTop );
@@ -2198,6 +2214,7 @@ USBHUB_FdoHandleDeviceControl(
2198
2214
// sanity checks
2199
2215
ASSERT (NodeConnectionInfo );
2200
2216
2217
+ KeAcquireGuardedMutex (& HubDeviceExtension -> HubMutexLock );
2201
2218
for (Index = 0 ; Index < USB_MAXCHILDREN ; Index ++ )
2202
2219
{
2203
2220
if (HubDeviceExtension -> ChildDeviceObject [Index ] == NULL )
@@ -2224,6 +2241,7 @@ USBHUB_FdoHandleDeviceControl(
2224
2241
}
2225
2242
break ;
2226
2243
}
2244
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
2227
2245
// done
2228
2246
Irp -> IoStatus .Information = sizeof (USB_NODE_INFORMATION );
2229
2247
Status = STATUS_SUCCESS ;
@@ -2244,6 +2262,7 @@ USBHUB_FdoHandleDeviceControl(
2244
2262
// sanity checks
2245
2263
ASSERT (NodeKey );
2246
2264
2265
+ KeAcquireGuardedMutex (& HubDeviceExtension -> HubMutexLock );
2247
2266
for (Index = 0 ; Index < USB_MAXCHILDREN ; Index ++ )
2248
2267
{
2249
2268
if (HubDeviceExtension -> ChildDeviceObject [Index ] == NULL )
@@ -2283,6 +2302,7 @@ USBHUB_FdoHandleDeviceControl(
2283
2302
NodeKey -> ActualLength = Length + sizeof (USB_NODE_CONNECTION_DRIVERKEY_NAME );
2284
2303
break ;
2285
2304
}
2305
+ KeReleaseGuardedMutex (& HubDeviceExtension -> HubMutexLock );
2286
2306
}
2287
2307
}
2288
2308
else if (IoStack -> Parameters .DeviceIoControl .IoControlCode == IOCTL_USB_GET_NODE_CONNECTION_NAME )
0 commit comments