Skip to contentSkip to conversation

Added error checking for msix_init.

PATCH In review Shreya Shrivastava 2 participants 2 messages Oct 16, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 4/4 Added error checking for msix_init.

Add checks for negative return value to uses of msix_init.

---
 hw/usb/hcd-xhci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/usb/hcd-xhci.c +0 -0
index 4acf0c6..cb854aa 100644
@@ -3705,10 +3705,11 @@ static void usb_xhci_realize(struct PCIDevice

*dev, Error **errp)

     if (xhci->msix != ON_OFF_AUTO_OFF) {
         /* TODO check for errors */
-        msix_init(dev, xhci->numintrs,
+        ret = msix_init(dev, xhci->numintrs,
                   &xhci->mem, 0, OFF_MSIX_TABLE,
                   &xhci->mem, 0, OFF_MSIX_PBA,
                   0x90);
+        assert(ret >= 0);
     }

}

Signature · 1 line
1.9.1
#1 lore raw
Quoted 14 lines · Shreya Shrivastava

Add checks for negative return value to uses of msix_init.

---
 hw/usb/hcd-xhci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/usb/hcd-xhci.c +0 -0
index 4acf0c6..cb854aa 100644
@@ -3705,10 +3705,11 @@ static void usb_xhci_realize(struct PCIDevice
 *dev, Error **errp)
 

hw/usb/hcd-xhci.c static void usb_xhci_realize(struct PCIDevice · line 3715

Quoted 10 lines
hw/usb/hcd-xhci.c +2 -1
     if (xhci->msix != ON_OFF_AUTO_OFF) {
         /* TODO check for errors */
-        msix_init(dev, xhci->numintrs,
+        ret = msix_init(dev, xhci->numintrs,
                   &xhci->mem, 0, OFF_MSIX_TABLE,
                   &xhci->mem, 0, OFF_MSIX_PBA,
                   0x90);
+        assert(ret >= 0);
     }
 }

Please handle the error instead of adding an assert:

1. Use error_setg_errno(errp, -ret, "MSI-X initialization failed") so the caller knows an error occurred.

2. Look at the resources initialized by this function and pick corresponding cleanup calls from usb_xhci_exit() so they are freed. For example xhci->mfwrap_timer was created so timer_free() needs to be called.

(This is easier if you can move the msix_init() call further up before resources are initialized just like the msi_init() call. But you need to check if msix_init() relies on anything before moving the call up.)