ref: 35b8a692679495606c09e3f023ddee744a8852b9
parent: 133900625619ca253759b43cf39073d1adca6fc3
author: cinap_lenrek <[email protected]>
date: Sat Dec 3 12:11:03 EST 2022
usbxhci: cleanup
--- a/sys/src/9/imx8/usbxhciimx.c
+++ b/sys/src/9/imx8/usbxhciimx.c
@@ -74,6 +74,8 @@
if(ctlrs[i] == nil){
uintptr base = VIRTIO + 0x8100000 + i*0x100000;
ctlr = xhcialloc((u32int*)base, base - KZERO, 0x100000);
+ if(ctlr == nil)
+ break;
ctlrs[i] = ctlr;
goto Found;
}
@@ -81,9 +83,9 @@
return -1;
Found:
- xhcilinkage(hp, ctlr);
hp->tbdf = BUSUNKNOWN;
hp->irq = IRQusb1 + i;
+ xhcilinkage(hp, ctlr);
if(i == 0){
iomuxpad("pad_gpio1_io13", "usb1_otg_oc", "~LVTTL ~HYS ~PUE ~ODE FAST 45_OHM");
--- a/sys/src/9/port/usbxhci.c
+++ b/sys/src/9/port/usbxhci.c
@@ -1799,9 +1799,9 @@
print("usbxhci: no memory for controller\n");
return nil;
}
+ ctlr->mmio = mmio;
ctlr->base = base;
ctlr->size = size;
- ctlr->mmio = mmio;
ctlr->dmaaddr = physaddr;
--- a/sys/src/9/port/usbxhcipci.c
+++ b/sys/src/9/port/usbxhcipci.c
@@ -83,11 +83,11 @@
static void
init(Hci *hp)
{
- Xhci *xhci = hp->aux;
- Pcidev *pcidev = xhci->aux;
+ Xhci *ctlr = hp->aux;
+ Pcidev *pcidev = ctlr->aux;
pcienable(pcidev);
- if(xhci->mmio[0] == -1){
+ if(ctlr->mmio[0] == -1){
pcidisable(pcidev);
error("controller vanished");
}
@@ -97,8 +97,8 @@
static void
shutdown(Hci *hp)
{
- Xhci *xhci = hp->aux;
- Pcidev *pcidev = xhci->aux;
+ Xhci *ctlr = hp->aux;
+ Pcidev *pcidev = ctlr->aux;
xhcishutdown(hp);
pcidisable(pcidev);
@@ -120,8 +120,10 @@
* Any adapter matches if no hp->port is supplied,
* otherwise the ports must match.
*/
- for(i = 0; i < nelem(ctlrs) && ctlrs[i] != nil; i++){
+ for(i = 0; i < nelem(ctlrs); i++){
ctlr = ctlrs[i];
+ if(ctlr == nil)
+ break;
if(ctlr->active == nil)
if(hp->port == 0 || hp->port == ctlr->base)
goto Found;
@@ -130,11 +132,12 @@
Found:
pcidev = ctlr->aux;
+ hp->irq = pcidev->intl;
+ hp->tbdf = pcidev->tbdf;
+
xhcilinkage(hp, ctlr);
hp->init = init;
hp->shutdown = shutdown;
- hp->irq = pcidev->intl;
- hp->tbdf = pcidev->tbdf;
return 0;
}