From: John Hodge Date: Mon, 6 Aug 2012 10:19:25 +0000 (+0800) Subject: USB - Added rudimentary device cleanup X-Git-Tag: rel0.15~706^2~67 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c3cdb7282e835c292abd295f4d154e912a7529d7;p=tpg%2Facess2.git USB - Added rudimentary device cleanup --- diff --git a/KernelLand/Modules/USB/Core/usb_devinit.c b/KernelLand/Modules/USB/Core/usb_devinit.c index 30807ff4..c5fd2ef3 100644 --- a/KernelLand/Modules/USB/Core/usb_devinit.c +++ b/KernelLand/Modules/USB/Core/usb_devinit.c @@ -292,14 +292,35 @@ void USB_DeviceConnected(tUSBHub *Hub, int Port) free(full_buf); } - + + Hub->Devices[Port] = dev; + // Done. LEAVE('-'); } void USB_DeviceDisconnected(tUSBHub *Hub, int Port) { - + tUSBDevice *dev; + if( !Hub->Devices[Port] ) { + Log_Error("USB", "Non-registered device disconnected"); + return; + } + dev = Hub->Devices[Port]; + + // TODO: Free related resources + // - Endpoint registrations + for( int i = 0; i < 16; i ++ ) + { + if(dev->EndpointHandles[i]) + dev->Host->HostDef->RemEndpoint(dev->Host->Ptr, dev->EndpointHandles[i]); + } + + // - Bus Address + USB_int_DeallocateAddress(dev->Host, dev->Address); + // - Inform handler + // - Allocate memory + free(dev); } void *USB_GetDeviceDataPtr(tUSBInterface *Dev) { return Dev->Data; }