diff --git a/kernel/device/storage/usbdrv.c b/kernel/device/storage/usbdrv.c index a34d2f2..86816c8 100644 --- a/kernel/device/storage/usbdrv.c +++ b/kernel/device/storage/usbdrv.c @@ -207,6 +207,8 @@ DEFINE_DEVICE_INIT (usbdrv_init) { usbdrv->xhci = init->xhci; usbdrv->usb_device = init->usb_device; + device->udata = usbdrv; + usbdrv_setup_endpoints (usbdrv); ret = @@ -236,4 +238,8 @@ DEFINE_DEVICE_INIT (usbdrv_init) { return true; } -DEFINE_DEVICE_FINI (usbdrv_fini) {} +DEFINE_DEVICE_FINI (usbdrv_fini) { + struct usbdrv* usbdrv = device->udata; + + free (usbdrv); +} diff --git a/kernel/device/usb/xhci.c b/kernel/device/usb/xhci.c index a1b6612..bde884c 100644 --- a/kernel/device/usb/xhci.c +++ b/kernel/device/usb/xhci.c @@ -69,17 +69,19 @@ static void xhci_delete_usb_device (struct xhci* xhci, struct xhci_port* xhci_po list_find (struct xhci_usb_device, xhci->xhci_usb_devices, usb_device, xhci_port->port_value, xhci_port->port_value, usb_devices_link); - device_delete (usb_device->device->key, proc, rctx); + if (usb_device != NULL) { + device_delete (usb_device->device->key, proc, rctx); - list_remove (xhci->xhci_usb_devices, &usb_device->usb_devices_link); + list_remove (xhci->xhci_usb_devices, &usb_device->usb_devices_link); - if (usb_device->endpoint0_ring.phys != 0) - pmm_free (usb_device->endpoint0_ring.phys, 1); + if (usb_device->endpoint0_ring.phys != 0) + pmm_free (usb_device->endpoint0_ring.phys, 1); - pmm_free (xhci->xhci_dcbaa[usb_device->slot_id], 1); - xhci->xhci_dcbaa[usb_device->slot_id] = 0; + pmm_free (xhci->xhci_dcbaa[usb_device->slot_id], 1); + xhci->xhci_dcbaa[usb_device->slot_id] = 0; - free (usb_device); + free (usb_device); + } } static void xhci_bios_handover (struct xhci* xhci) {