mirror of
https://github.com/hathach/tinyusb.git
synced 2025-10-29 19:49:07 +00:00
fix some warnings detected by pvs-studio
This commit is contained in:
parent
e93e47ae04
commit
2f3b21a1e5
@ -45,6 +45,7 @@ int main(void) {
|
||||
|
||||
uint32_t start_ms = 0;
|
||||
bool led_state = false;
|
||||
const size_t hello_len = strlen(HELLO_STR);
|
||||
|
||||
while (1) {
|
||||
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
|
||||
@ -66,7 +67,7 @@ int main(void) {
|
||||
printf(HELLO_STR);
|
||||
|
||||
#ifndef LOGGER_UART
|
||||
board_uart_write(HELLO_STR, strlen(HELLO_STR));
|
||||
board_uart_write(HELLO_STR, hello_len);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -126,9 +126,9 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uin
|
||||
const char pid[] = "Mass Storage";
|
||||
const char rev[] = "1.0";
|
||||
|
||||
memcpy(inquiry_resp->vendor_id, vid, strlen(vid));
|
||||
memcpy(inquiry_resp->product_id, pid, strlen(pid));
|
||||
memcpy(inquiry_resp->product_rev, rev, strlen(rev));
|
||||
strncpy((char*) inquiry_resp->vendor_id, vid, 8);
|
||||
strncpy((char*) inquiry_resp->product_id, pid, 16);
|
||||
strncpy((char*) inquiry_resp->product_rev, rev, 4);
|
||||
|
||||
return sizeof(scsi_inquiry_resp_t); // 36 bytes
|
||||
}
|
||||
@ -242,6 +242,8 @@ int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, u
|
||||
// negative means error -> tinyusb could stall and/or response with failed status
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -198,9 +198,9 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t* inquiry_resp, uin
|
||||
const char pid[] = "Mass Storage";
|
||||
const char rev[] = "1.0";
|
||||
|
||||
memcpy(inquiry_resp->vendor_id, vid, strlen(vid));
|
||||
memcpy(inquiry_resp->product_id, pid, strlen(pid));
|
||||
memcpy(inquiry_resp->product_rev, rev, strlen(rev));
|
||||
strncpy((char*) inquiry_resp->vendor_id, vid, 8);
|
||||
strncpy((char*) inquiry_resp->product_id, pid, 16);
|
||||
strncpy((char*) inquiry_resp->product_rev, rev, 4);
|
||||
|
||||
return sizeof(scsi_inquiry_resp_t); // 36 bytes
|
||||
}
|
||||
@ -324,12 +324,8 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
|
||||
// - READ10 and WRITE10 has their own callbacks
|
||||
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) {
|
||||
// read10 & write10 has their own callback and MUST not be handled here
|
||||
|
||||
void const *response = NULL;
|
||||
int32_t resplen = 0;
|
||||
|
||||
// most scsi handled is input
|
||||
bool in_xfer = true;
|
||||
(void) buffer;
|
||||
(void) bufsize;
|
||||
|
||||
switch (scsi_cmd[0]) {
|
||||
default:
|
||||
@ -337,22 +333,10 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
|
||||
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
|
||||
|
||||
// negative means error -> tinyusb could stall and/or response with failed status
|
||||
resplen = -1;
|
||||
break;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// return resplen must not larger than bufsize
|
||||
if (resplen > bufsize) { resplen = bufsize; }
|
||||
|
||||
if (response && (resplen > 0)) {
|
||||
if (in_xfer) {
|
||||
memcpy(buffer, response, (size_t) resplen);
|
||||
} else {
|
||||
// SCSI output
|
||||
}
|
||||
}
|
||||
|
||||
return (int32_t) resplen;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -126,9 +126,9 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uin
|
||||
const char pid[] = "Mass Storage";
|
||||
const char rev[] = "1.0";
|
||||
|
||||
memcpy(inquiry_resp->vendor_id, vid, strlen(vid));
|
||||
memcpy(inquiry_resp->product_id, pid, strlen(pid));
|
||||
memcpy(inquiry_resp->product_rev, rev, strlen(rev));
|
||||
strncpy((char*) inquiry_resp->vendor_id, vid, 8);
|
||||
strncpy((char*) inquiry_resp->product_id, pid, 16);
|
||||
strncpy((char*) inquiry_resp->product_rev, rev, 4);
|
||||
|
||||
return sizeof(scsi_inquiry_resp_t); // 36 bytes
|
||||
}
|
||||
@ -211,42 +211,21 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
|
||||
// Callback invoked when received an SCSI command not in built-in list below
|
||||
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
|
||||
// - READ10 and WRITE10 has their own callbacks
|
||||
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize)
|
||||
{
|
||||
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) {
|
||||
// read10 & write10 has their own callback and MUST not be handled here
|
||||
(void) buffer;
|
||||
(void) bufsize;
|
||||
|
||||
void const* response = NULL;
|
||||
int32_t resplen = 0;
|
||||
|
||||
// most scsi handled is input
|
||||
bool in_xfer = true;
|
||||
|
||||
switch (scsi_cmd[0])
|
||||
{
|
||||
switch (scsi_cmd[0]) {
|
||||
default:
|
||||
// Set Sense = Invalid Command Operation
|
||||
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
|
||||
|
||||
// negative means error -> tinyusb could stall and/or response with failed status
|
||||
resplen = -1;
|
||||
break;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// return resplen must not larger than bufsize
|
||||
if ( resplen > bufsize ) resplen = bufsize;
|
||||
|
||||
if ( response && (resplen > 0) )
|
||||
{
|
||||
if(in_xfer)
|
||||
{
|
||||
memcpy(buffer, response, (size_t) resplen);
|
||||
}else
|
||||
{
|
||||
// SCSI output
|
||||
}
|
||||
}
|
||||
|
||||
return resplen;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -217,9 +217,9 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uin
|
||||
const char pid[] = "Mass Storage";
|
||||
const char rev[] = "1.0";
|
||||
|
||||
memcpy(inquiry_resp->vendor_id, vid, strlen(vid));
|
||||
memcpy(inquiry_resp->product_id, pid, strlen(pid));
|
||||
memcpy(inquiry_resp->product_rev, rev, strlen(rev));
|
||||
strncpy((char*) inquiry_resp->vendor_id, vid, 8);
|
||||
strncpy((char*) inquiry_resp->product_id, pid, 16);
|
||||
strncpy((char*) inquiry_resp->product_rev, rev, 4);
|
||||
|
||||
return sizeof(scsi_inquiry_resp_t); // 36 bytes
|
||||
}
|
||||
@ -227,9 +227,7 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uin
|
||||
// Invoked when received Test Unit Ready command.
|
||||
// return true allowing host to read/write this LUN e.g SD card inserted
|
||||
bool tud_msc_test_unit_ready_cb(uint8_t lun) {
|
||||
if ( lun == 1 && board_button_read() ) return false;
|
||||
|
||||
return true; // RAM disk is always ready
|
||||
return ( lun == 1 && board_button_read() ) ? false : true;
|
||||
}
|
||||
|
||||
// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
|
||||
|
||||
@ -131,7 +131,7 @@ void board_init(void) {
|
||||
|
||||
#elif CFG_TUSB_OS == OPT_OS_FREERTOS
|
||||
// Explicitly disable systick to prevent its ISR runs before scheduler start
|
||||
SysTick->CTRL &= ~1U;
|
||||
SysTick->CTRL &= ~1UL;
|
||||
|
||||
// If freeRTOS is used, IRQ priority is limit by max syscall ( smaller is higher )
|
||||
#ifdef USB_OTG_FS_PERIPH_BASE
|
||||
|
||||
@ -533,7 +533,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
// Check for wanted char and invoke callback if needed
|
||||
if (((signed char) p_cdc->wanted_char) != -1) {
|
||||
for (uint32_t i = 0; i < xferred_bytes; i++) {
|
||||
if ((p_cdc->wanted_char == p_epbuf->epout[i]) && !tu_fifo_empty(&p_cdc->rx_ff)) {
|
||||
if ((p_cdc->wanted_char == (char) p_epbuf->epout[i]) && !tu_fifo_empty(&p_cdc->rx_ff)) {
|
||||
tud_cdc_rx_wanted_cb(itf, p_cdc->wanted_char);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1136,7 +1136,6 @@ static inline bool ftdi_sio_reset(cdch_interface_t *p_cdc, tuh_xfer_cb_t complet
|
||||
|
||||
// internal control complete to update state such as line state, line_coding
|
||||
static void ftdi_internal_control_complete(cdch_interface_t* p_cdc, tuh_xfer_t *xfer) {
|
||||
TU_VERIFY(xfer->result == XFER_RESULT_SUCCESS,);
|
||||
const tusb_control_request_t * setup = xfer->setup;
|
||||
if (xfer->result == XFER_RESULT_SUCCESS) {
|
||||
if (setup->bRequest == FTDI_SIO_SET_MODEM_CTRL_REQUEST &&
|
||||
|
||||
@ -100,10 +100,10 @@ typedef enum {
|
||||
} tusb_xfer_type_t;
|
||||
|
||||
typedef enum {
|
||||
TUSB_DIR_OUT = 0,
|
||||
TUSB_DIR_IN = 1,
|
||||
TUSB_DIR_OUT = 0u,
|
||||
TUSB_DIR_IN = 1u,
|
||||
|
||||
TUSB_DIR_IN_MASK = 0x80
|
||||
TUSB_DIR_IN_MASK = 0x80u
|
||||
} tusb_dir_t;
|
||||
|
||||
enum {
|
||||
@ -350,7 +350,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bNumConfigurations ; ///< Number of possible configurations.
|
||||
} tusb_desc_device_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_device_t) == 18, "size is not correct");
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_device_t) == 18u, "size is not correct");
|
||||
|
||||
// USB Binary Device Object Store (BOS) Descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
@ -360,7 +360,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bNumDeviceCaps ; ///< Number of device capability descriptors in the BOS
|
||||
} tusb_desc_bos_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_bos_t) == 5, "size is not correct");
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_bos_t) == 5u, "size is not correct");
|
||||
|
||||
/// USB Configuration Descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
@ -375,7 +375,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
|
||||
} tusb_desc_configuration_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_configuration_t) == 9, "size is not correct");
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_configuration_t) == 9u, "size is not correct");
|
||||
|
||||
/// USB Interface Descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
@ -391,7 +391,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t iInterface ; ///< Index of string descriptor describing this interface
|
||||
} tusb_desc_interface_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_interface_t) == 9, "size is not correct");
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_interface_t) == 9u, "size is not correct");
|
||||
|
||||
/// USB Endpoint Descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
@ -411,7 +411,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bInterval ; // Polling interval, in frames or microframes depending on the operating speed
|
||||
} tusb_desc_endpoint_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_endpoint_t) == 7, "size is not correct");
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_endpoint_t) == 7u, "size is not correct");
|
||||
|
||||
/// USB Other Speed Configuration Descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
@ -441,7 +441,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t bReserved ; ///< Reserved for future use, must be zero
|
||||
} tusb_desc_device_qualifier_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_device_qualifier_t) == 10, "size is not correct");
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_device_qualifier_t) == 10u, "size is not correct");
|
||||
|
||||
/// USB Interface Association Descriptor (IAD ECN)
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
@ -458,7 +458,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint8_t iFunction ; ///< Index of the string descriptor describing the interface association.
|
||||
} tusb_desc_interface_assoc_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_interface_assoc_t) == 8, "size is not correct");
|
||||
TU_VERIFY_STATIC( sizeof(tusb_desc_interface_assoc_t) == 8u, "size is not correct");
|
||||
|
||||
// USB String Descriptor
|
||||
typedef struct TU_ATTR_PACKED {
|
||||
@ -528,7 +528,7 @@ typedef struct TU_ATTR_PACKED {
|
||||
uint16_t wLength;
|
||||
} tusb_control_request_t;
|
||||
|
||||
TU_VERIFY_STATIC( sizeof(tusb_control_request_t) == 8, "size is not correct");
|
||||
TU_VERIFY_STATIC( sizeof(tusb_control_request_t) == 8u, "size is not correct");
|
||||
|
||||
TU_ATTR_PACKED_END // End of all packed definitions
|
||||
TU_ATTR_BIT_FIELD_ORDER_END
|
||||
|
||||
@ -299,7 +299,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
|
||||
// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
|
||||
#define TUD_HID_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epin, _epsize, _ep_interval) \
|
||||
/* Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_HID, (uint8_t)((_boot_protocol) ? (uint8_t)HID_SUBCLASS_BOOT : 0), _boot_protocol, _stridx,\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_HID, (uint8_t)((_boot_protocol != HID_ITF_PROTOCOL_NONE) ? (uint8_t)HID_SUBCLASS_BOOT : 0u), _boot_protocol, _stridx,\
|
||||
/* HID descriptor */\
|
||||
9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
|
||||
/* Endpoint In */\
|
||||
@ -312,7 +312,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
|
||||
// Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval
|
||||
#define TUD_HID_INOUT_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epout, _epin, _epsize, _ep_interval) \
|
||||
/* Interface */\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_HID, (uint8_t)((_boot_protocol) ? (uint8_t)HID_SUBCLASS_BOOT : 0), _boot_protocol, _stridx,\
|
||||
9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_HID, (uint8_t)((_boot_protocol != HID_ITF_PROTOCOL_NONE) ? (uint8_t)HID_SUBCLASS_BOOT : 0u), _boot_protocol, _stridx,\
|
||||
/* HID descriptor */\
|
||||
9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
|
||||
/* Endpoint Out */\
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user