From 4d21beb957c9481e57a0403112e712bceb71ef0a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Herv=C3=A9=20Poussineau?= Date: Sat, 24 Dec 2005 17:56:23 +0000 Subject: [PATCH] Allow more than one USB controller svn path=/trunk/; revision=20323 --- reactos/drivers/usb/miniport/common/main.c | 42 +++++++++++++++------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/reactos/drivers/usb/miniport/common/main.c b/reactos/drivers/usb/miniport/common/main.c index 5f7cc83126d..a13f599c23a 100644 --- a/reactos/drivers/usb/miniport/common/main.c +++ b/reactos/drivers/usb/miniport/common/main.c @@ -197,7 +197,8 @@ AddDevice( UNICODE_STRING LinkDeviceName; PUSBMP_DRIVER_EXTENSION DriverExtension; PUSBMP_DEVICE_EXTENSION DeviceExtension; - ULONG DeviceNumber; + static ULONG DeviceNumber = 0; + BOOL AlreadyRestarted = FALSE; // Allocate driver extension now DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject); @@ -216,18 +217,33 @@ AddDevice( } } - // Create a unicode device name - DeviceNumber = 0; //TODO: Allocate new device number every time - swprintf(DeviceBuffer, L"\\Device\\USBFDO-%lu", DeviceNumber); - RtlInitUnicodeString(&DeviceName, DeviceBuffer); - - Status = IoCreateDevice(DriverObject, - sizeof(USBMP_DEVICE_EXTENSION), - &DeviceName, - FILE_DEVICE_BUS_EXTENDER, - 0, - FALSE, - &fdo); + /* Create a unicode device name. Allocate a new device number every time */ + do + { + DeviceNumber++; + if (DeviceNumber == 9999) + { + /* Hmm. We don't have a free number. */ + if (AlreadyRestarted) + { + Status = STATUS_UNSUCCESSFUL; + break; + } + /* Start again at DeviceNumber = 0 to find a free number */ + DeviceNumber = 0; + AlreadyRestarted = TRUE; + } + swprintf(DeviceBuffer, L"\\Device\\USBFDO-%lu", DeviceNumber); + RtlInitUnicodeString(&DeviceName, DeviceBuffer); + + Status = IoCreateDevice(DriverObject, + sizeof(USBMP_DEVICE_EXTENSION), + &DeviceName, + FILE_DEVICE_BUS_EXTENDER, + 0, + FALSE, + &fdo); + } while (Status == STATUS_OBJECT_NAME_COLLISION); if (!NT_SUCCESS(Status)) { -- 2.17.1