Skip to content

Commit 7369090

Browse files
author
Felipe Balbi
committed
usb: dwc3: gadget: make Set Endpoint Configuration macros safe
Some gadget drivers are bad, bad boys. We notice that ADB was passing bad Burst Size which caused top bits of param0 to be overwritten which confused DWC3 when running this command. In order to avoid future issues, we're going to make sure values passed by macros are always safe for the controller. Note that ADB still needs a fix to *not* pass bad values. Cc: <[email protected]> # v3.2+ Reported-by: Mohamed Abbas <[email protected]> Sugested-by: Adam Andruszak <[email protected]> Signed-off-by: Felipe Balbi <[email protected]>
1 parent c1ae3cf commit 7369090

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/usb/dwc3/gadget.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,23 @@ struct dwc3;
2828
#define gadget_to_dwc(g) (container_of(g, struct dwc3, gadget))
2929

3030
/* DEPCFG parameter 1 */
31-
#define DWC3_DEPCFG_INT_NUM(n) ((n) << 0)
31+
#define DWC3_DEPCFG_INT_NUM(n) (((n) & 0x1f) << 0)
3232
#define DWC3_DEPCFG_XFER_COMPLETE_EN (1 << 8)
3333
#define DWC3_DEPCFG_XFER_IN_PROGRESS_EN (1 << 9)
3434
#define DWC3_DEPCFG_XFER_NOT_READY_EN (1 << 10)
3535
#define DWC3_DEPCFG_FIFO_ERROR_EN (1 << 11)
3636
#define DWC3_DEPCFG_STREAM_EVENT_EN (1 << 13)
37-
#define DWC3_DEPCFG_BINTERVAL_M1(n) ((n) << 16)
37+
#define DWC3_DEPCFG_BINTERVAL_M1(n) (((n) & 0xff) << 16)
3838
#define DWC3_DEPCFG_STREAM_CAPABLE (1 << 24)
39-
#define DWC3_DEPCFG_EP_NUMBER(n) ((n) << 25)
39+
#define DWC3_DEPCFG_EP_NUMBER(n) (((n) & 0x1f) << 25)
4040
#define DWC3_DEPCFG_BULK_BASED (1 << 30)
4141
#define DWC3_DEPCFG_FIFO_BASED (1 << 31)
4242

4343
/* DEPCFG parameter 0 */
44-
#define DWC3_DEPCFG_EP_TYPE(n) ((n) << 1)
45-
#define DWC3_DEPCFG_MAX_PACKET_SIZE(n) ((n) << 3)
46-
#define DWC3_DEPCFG_FIFO_NUMBER(n) ((n) << 17)
47-
#define DWC3_DEPCFG_BURST_SIZE(n) ((n) << 22)
44+
#define DWC3_DEPCFG_EP_TYPE(n) (((n) & 0x3) << 1)
45+
#define DWC3_DEPCFG_MAX_PACKET_SIZE(n) (((n) & 0x7ff) << 3)
46+
#define DWC3_DEPCFG_FIFO_NUMBER(n) (((n) & 0x1f) << 17)
47+
#define DWC3_DEPCFG_BURST_SIZE(n) (((n) & 0xf) << 22)
4848
#define DWC3_DEPCFG_DATA_SEQ_NUM(n) ((n) << 26)
4949
/* This applies for core versions earlier than 1.94a */
5050
#define DWC3_DEPCFG_IGN_SEQ_NUM (1 << 31)

0 commit comments

Comments
 (0)