[PATCH v2] usb: musb: gadget: stall when SETUP packet size is invalid

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

 



This is required by the USB Specs.
Also dump the fifo for debug purpose.

Signed-off-by: Bin Liu <b-liu@xxxxxx>
---

v2:
  
- Modification based on Felipe's comments
  * Added commit log;
  * Wrapped dump fifo function with #ifdef DEBUG;
  * Used static buffer for dump;
  * Changed dump level to KERN_DEBUG;
- Changed the dump fifo function to inline;
- Set MUSB_CSR0_P_DATAEND bit to avoid confusing log;


 drivers/usb/musb/musb_gadget_ep0.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb/musb_gadget_ep0.c b/drivers/usb/musb/musb_gadget_ep0.c
index 2af45a0..af9e7de 100644
--- a/drivers/usb/musb/musb_gadget_ep0.c
+++ b/drivers/usb/musb/musb_gadget_ep0.c
@@ -658,6 +658,23 @@ __acquires(musb->lock)
 	return retval;
 }
 
+/* dump the EP0 fifo for debug */
+static inline void musb_g_ep0_dump_fifo(struct musb *musb, int len)
+{
+#ifdef DEBUG
+#define BUF_LEN	16
+
+	u8 buf[BUF_LEN];
+
+	if (len <= 0)
+		return;
+
+	musb->ops->read_fifo(&musb->endpoints[0], min(len, BUF_LEN), buf);
+	print_hex_dump(KERN_DEBUG, "packet: ", DUMP_PREFIX_NONE,
+			16, 1, buf, len, false);
+#endif /* DEBUG */
+}
+
 /*
  * Handle peripheral ep0 interrupt
  *
@@ -802,7 +819,16 @@ setup:
 
 			if (len != 8) {
 				ERR("SETUP packet len %d != 8 ?\n", len);
-				break;
+				musb_g_ep0_dump_fifo(musb, len);
+				/*
+				 * set the DATAEND bit here to
+				 * help avoid SetupEnd interrupt coming
+				 * in the idle stage when we're stalling...
+				 */
+				musb->ackpend = MUSB_CSR0_P_SVDRXPKTRDY |
+						MUSB_CSR0_P_DATAEND;
+				retval = IRQ_HANDLED;
+				goto stall;
 			}
 			musb_read_setup(musb, &setup);
 			retval = IRQ_HANDLED;
-- 
1.8.4

--
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