Skip to content

Commit 2e29d1c

Browse files
authored
Merge pull request #3293
ESP32-S3 bulk transfer issues #3154
2 parents 33b6954 + aa0fc2e commit 2e29d1c

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

src/common/tusb_common.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,35 @@ extern void* tusb_app_phys_to_virt(void *phys_addr);
109109

110110
// This is a backport of memset_s from c11
111111
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count) {
112-
// TODO may check if desst and src is not NULL
113-
if ( count > destsz ) {
112+
// Validate parameters
113+
if (dest == NULL) {
114114
return -1;
115115
}
116+
117+
if (count > destsz) {
118+
return -1;
119+
}
120+
116121
memset(dest, ch, count);
117122
return 0;
118123
}
119124

120125
// This is a backport of memcpy_s from c11
121126
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void *src, size_t count) {
122-
// TODO may check if desst and src is not NULL
123-
if ( count > destsz ) {
127+
// Validate parameters
128+
if (dest == NULL) {
124129
return -1;
125130
}
131+
132+
// For memcpy, src may be NULL only if count == 0. Reject otherwise.
133+
if (src == NULL && count != 0) {
134+
return -1;
135+
}
136+
137+
if (count > destsz) {
138+
return -1;
139+
}
140+
126141
memcpy(dest, src, count);
127142
return 0;
128143
}

src/portable/synopsys/dwc2/dcd_dwc2.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -814,17 +814,18 @@ static void handle_rxflvl_irq(uint8_t rhport) {
814814
dfifo_read_packet(dwc2, xfer->buffer, byte_count);
815815
xfer->buffer += byte_count;
816816
}
817+
}
817818

818-
// short packet, minus remaining bytes (xfer_size)
819-
if (byte_count < xfer->max_size) {
820-
const dwc2_ep_tsize_t tsiz = {.value = epout->tsiz};
821-
xfer->total_len -= tsiz.xfer_size;
822-
if (epnum == 0) {
823-
xfer->total_len -= _dcd_data.ep0_pending[TUSB_DIR_OUT];
824-
_dcd_data.ep0_pending[TUSB_DIR_OUT] = 0;
825-
}
819+
// short packet (including ZLP when byte_count == 0), minus remaining bytes (xfer_size)
820+
if (byte_count < xfer->max_size) {
821+
const dwc2_ep_tsize_t tsiz = {.value = epout->tsiz};
822+
xfer->total_len -= tsiz.xfer_size;
823+
if (epnum == 0) {
824+
xfer->total_len -= _dcd_data.ep0_pending[TUSB_DIR_OUT];
825+
_dcd_data.ep0_pending[TUSB_DIR_OUT] = 0;
826826
}
827827
}
828+
828829
break;
829830
}
830831

0 commit comments

Comments
 (0)