Skip to content

Commit e34aeb5

Browse files
committed
minor clean up
1 parent 2e47210 commit e34aeb5

File tree

7 files changed

+29
-35
lines changed

7 files changed

+29
-35
lines changed

src/class/audio/audio_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,7 @@ bool tud_audio_buffer_and_schedule_control_xfer(uint8_t rhport, tusb_control_req
21992199
if (len > _audiod_fct[func_id].ctrl_buf_sz) len = _audiod_fct[func_id].ctrl_buf_sz;
22002200

22012201
// Copy into buffer
2202-
TU_VERIFY(tu_memcpy_s(_audiod_fct[func_id].ctrl_buf, sizeof(_audiod_fct[func_id].ctrl_buf), data, (size_t)len)==0);
2202+
TU_VERIFY(0 == tu_memcpy_s(_audiod_fct[func_id].ctrl_buf, sizeof(_audiod_fct[func_id].ctrl_buf), data, (size_t)len));
22032203

22042204
// Schedule transmit
22052205
return tud_control_xfer(rhport, p_request, (void*)_audiod_fct[func_id].ctrl_buf, len);

src/class/hid/hid_device.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, u
9393
if (report_id)
9494
{
9595
p_hid->epin_buf[0] = report_id;
96-
TU_VERIFY(tu_memcpy_s(p_hid->epin_buf+1, CFG_TUD_HID_EP_BUFSIZE-1, report, len)==0);
96+
TU_VERIFY(0 == tu_memcpy_s(p_hid->epin_buf+1, CFG_TUD_HID_EP_BUFSIZE-1, report, len));
9797
len++;
9898
}else
9999
{
100-
TU_VERIFY(tu_memcpy_s(p_hid->epin_buf, CFG_TUD_HID_EP_BUFSIZE, report, len)==0);
100+
TU_VERIFY(0 == tu_memcpy_s(p_hid->epin_buf, CFG_TUD_HID_EP_BUFSIZE, report, len));
101101
}
102102

103103
return usbd_edpt_xfer(rhport, p_hid->ep_in, p_hid->epin_buf, len);
@@ -122,7 +122,7 @@ bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modi
122122

123123
if ( keycode )
124124
{
125-
TU_VERIFY(tu_memcpy_s(report.keycode, sizeof(report.keycode), keycode, sizeof(report.keycode))==0);
125+
memcpy(report.keycode, keycode, sizeof(report.keycode));
126126
}else
127127
{
128128
tu_memclr(report.keycode, 6);

src/class/midi/midi_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ uint32_t tud_midi_n_stream_read(uint8_t itf, uint8_t cable_num, void* buffer, ui
182182
uint8_t const count = (uint8_t) tu_min32(stream->total - stream->index, bufsize);
183183

184184
// Skip the header (1st byte) in the buffer
185-
TU_VERIFY(tu_memcpy_s(buf8, bufsize, stream->buffer + 1 + stream->index, count)==0);
185+
TU_VERIFY(0 == tu_memcpy_s(buf8, bufsize, stream->buffer + 1 + stream->index, count));
186186

187187
total_read += count;
188188
stream->index += count;

src/class/msc/msc_device.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
707707
read_capa10.block_size = tu_htonl(block_size);
708708

709709
resplen = sizeof(read_capa10);
710-
TU_VERIFY(tu_memcpy_s(buffer, bufsize, &read_capa10, (size_t) resplen));
710+
TU_VERIFY(0 == tu_memcpy_s(buffer, bufsize, &read_capa10, (size_t) resplen));
711711
}
712712
}
713713
break;
@@ -741,7 +741,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
741741
read_fmt_capa.block_size_u16 = tu_htons(block_size);
742742

743743
resplen = sizeof(read_fmt_capa);
744-
TU_VERIFY(tu_memcpy_s(buffer, bufsize, &read_fmt_capa, (size_t) resplen)==0);
744+
TU_VERIFY(0 == tu_memcpy_s(buffer, bufsize, &read_fmt_capa, (size_t) resplen));
745745
}
746746
}
747747
break;
@@ -764,7 +764,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
764764
tud_msc_inquiry_cb(lun, inquiry_rsp.vendor_id, inquiry_rsp.product_id, inquiry_rsp.product_rev);
765765

766766
resplen = sizeof(inquiry_rsp);
767-
TU_VERIFY(tu_memcpy_s(buffer, bufsize, &inquiry_rsp, (size_t) resplen)==0);
767+
TU_VERIFY(0 == tu_memcpy_s(buffer, bufsize, &inquiry_rsp, (size_t) resplen));
768768
}
769769
break;
770770

@@ -788,7 +788,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
788788
mode_resp.write_protected = !writable;
789789

790790
resplen = sizeof(mode_resp);
791-
TU_VERIFY(tu_memcpy_s(buffer, bufsize, &mode_resp, (size_t) resplen)==0);
791+
TU_VERIFY(0 == tu_memcpy_s(buffer, bufsize, &mode_resp, (size_t) resplen));
792792
}
793793
break;
794794

@@ -806,7 +806,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
806806
sense_rsp.add_sense_qualifier = p_msc->add_sense_qualifier;
807807

808808
resplen = sizeof(sense_rsp);
809-
TU_VERIFY(tu_memcpy_s(buffer, bufsize, &sense_rsp, (size_t) resplen)==0);
809+
TU_VERIFY(0 == tu_memcpy_s(buffer, bufsize, &sense_rsp, (size_t) resplen));
810810

811811
// request sense callback could overwrite the sense data
812812
if (tud_msc_request_sense_cb)

src/common/tusb_common.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,26 @@
8484
#define tu_varclr(_var) tu_memclr(_var, sizeof(*(_var)))
8585

8686
// This is a backport of memset_s from c11
87-
int32_t tu_memset_s(void *dest, size_t destsz, int ch, size_t count);
87+
TU_ATTR_ALWAYS_INLINE static inline int tu_memset_s(void *dest, size_t destsz, int ch, size_t count)
88+
{
89+
// TODO may check if desst and src is not NULL
90+
if (count > destsz) {
91+
return -1;
92+
}
93+
memset(dest, ch, count);
94+
return 0;
95+
}
8896

8997
// This is a backport of memcpy_s from c11
90-
int32_t tu_memcpy_s(void *dest, size_t destsz,
91-
const void * src, size_t count );
98+
TU_ATTR_ALWAYS_INLINE static inline int tu_memcpy_s(void *dest, size_t destsz, const void * src, size_t count )
99+
{
100+
// TODO may check if desst and src is not NULL
101+
if (count > destsz) {
102+
return -1;
103+
}
104+
memcpy(dest, src, count);
105+
return 0;
106+
}
92107

93108

94109
//------------- Bytes -------------//

src/device/usbd_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static bool _data_stage_xact(uint8_t rhport)
9494
{
9595
ep_addr = EDPT_CTRL_IN;
9696
if ( xact_len ) {
97-
TU_VERIFY(tu_memcpy_s(_usbd_ctrl_buf, CFG_TUD_ENDPOINT0_SIZE, _ctrl_xfer.buffer, xact_len)==0);
97+
TU_VERIFY(0 == tu_memcpy_s(_usbd_ctrl_buf, CFG_TUD_ENDPOINT0_SIZE, _ctrl_xfer.buffer, xact_len));
9898
}
9999
}
100100

src/tusb.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* This file is part of the TinyUSB stack.
2525
*/
2626

27-
#include "common/tusb_common.h"
2827
#include "tusb_option.h"
2928

3029
#if CFG_TUH_ENABLED || CFG_TUD_ENABLED
@@ -487,23 +486,3 @@ void tu_print_mem(void const *buf, uint32_t count, uint8_t indent)
487486
#endif
488487

489488
#endif // host or device enabled
490-
491-
//--------------------------------------------------------------------+
492-
// Common
493-
//--------------------------------------------------------------------+
494-
495-
int32_t tu_memset_s(void *dest, size_t destsz, int ch, size_t count) {
496-
if (count > destsz) {
497-
return -1;
498-
}
499-
memset(dest, ch, count);
500-
return 0;
501-
}
502-
503-
int32_t tu_memcpy_s(void *dest, size_t destsz, const void *src, size_t count) {
504-
if (count > destsz) {
505-
return -1;
506-
}
507-
memcpy(dest, src, count);
508-
return 0;
509-
}

0 commit comments

Comments
 (0)