possible error in xhci-ring.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I think I see a possible error in xhci-ring.c.  When doing a build (of
current -next or 2.6.39-rc1) I get the warning:

drivers/usb/host/xhci-ring.c:1229:18: warning: â??hcdâ?? may be used
uninitialized in this function

Looking at handle_port_status(), it appears that it is indeed possible
for this function to call usb_hcd_poll_rh_status(hcd), by way of goto
cleanup in error cases, before hcd has been initialized. I believe the
fix is to initialize hcd to NULL and then only call
usb_hcd_poll_rh_status() if hcd is not NULL.

If, indeed, that's the correct way to deal with it, here's a patch.

------------------

From: Bill Pemberton <wfp5p@xxxxxxxxxxxx>

xhci: do not call usb_hcd_poll_rh_status with uinititialized hcd

Fixes the follow compilation warning:

drivers/usb/host/xhci-ring.c:1229:18: warning: â??hcdâ?? may be used uninitialized in this function

It was possible for hcd to be used uninitialized if the error
conditions before hcd is initialized jump to cleanup:, which would pass
the uninitialized hcd structure to usb_hcd_poll_rh_status.

Signed-off-by: Bill Pemberton <wfp5p@xxxxxxxxxxxx>
---
 drivers/usb/host/xhci-ring.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index cfc1ad9..fa7ec6f 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1226,7 +1226,7 @@ static unsigned int find_faked_portnum_from_hw_portnum(struct usb_hcd *hcd,
 static void handle_port_status(struct xhci_hcd *xhci,
 		union xhci_trb *event)
 {
-	struct usb_hcd *hcd;
+	struct usb_hcd *hcd = NULL;
 	u32 port_id;
 	u32 temp, temp1;
 	int max_ports;
@@ -1335,10 +1335,12 @@ cleanup:
 	/* Update event ring dequeue pointer before dropping the lock */
 	inc_deq(xhci, xhci->event_ring, true);
 
-	spin_unlock(&xhci->lock);
-	/* Pass this up to the core */
-	usb_hcd_poll_rh_status(hcd);
-	spin_lock(&xhci->lock);
+	if (hcd != NULL) {
+		spin_unlock(&xhci->lock);
+		/* Pass this up to the core */
+		usb_hcd_poll_rh_status(hcd);
+		spin_lock(&xhci->lock);
+	}
 }
 
 /*

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux