[v3,2/6] usb: xhci: return ERR_PTR(-ETIMEDOUT) at the end of xhci_wait_for_event()

Message ID 1515548724-31869-3-git-send-email-yamada.masahiro@socionext.com
State New
Headers show
  • assert() is almost used in the same way as BUG_ON(), except:
Related show

Commit Message

Masahiro Yamada Jan. 10, 2018, 1:45 a.m.
xhci_wait_for_event() is supposed to return a pointer to union xhci_trb,
but it does not return anything at the end of the function.

This relies on that the end of the function is unreachable due to BUG().

We are planning to make BUG() no-op for platforms with strong image size
constraint.  Doing so would cause compiler warning:

drivers/usb/host/xhci-ring.c:475:1: warning: control reaches end of non-void function [-Wreturn-type]

So, this function must return something.  From the error message just
above, ERR_PTR(-ETIMEDOUT) seems a good choice.

The use of BUG() looks suspicious here in the first place; no response
from hardware is not a bug.  It should be treated as a normal error.
So, this function must return an error pointer instead of BUG(), then
the caller must handle it properly.

I am not fixing the code because this is not the only place that stops
the system.  Just one failure of xHCI halts the system, here and there.

I left a comment block, hoping somebody will take a look.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

Changes in v3:
  - newly added

Changes in v2: None

 drivers/usb/host/xhci-ring.c | 7 +++++++
 1 file changed, 7 insertions(+)


diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 579e670..d780367 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -471,7 +471,14 @@  union xhci_trb *xhci_wait_for_event(struct xhci_ctrl *ctrl, trb_type expected)
 		return NULL;
 	printf("XHCI timeout on event type %d... cannot recover.\n", expected);
+	/*
+	 * CHECK:
+	 * Is this software bug?  Is this a good reason to halt the system?
+	 */