From a5f516893bbd539f11fb8d1cbb5b6db5a50fc632 Mon Sep 17 00:00:00 2001 From: hathach Date: Sun, 17 Oct 2021 16:26:27 +0700 Subject: more with -Wcast-qual --- src/host/usbh.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/host') diff --git a/src/host/usbh.c b/src/host/usbh.c index 2ef936ad0..53e8b9715 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -894,11 +894,10 @@ static bool enum_get_9byte_config_desc_complete(uint8_t dev_addr, tusb_control_r TU_ASSERT(XFER_RESULT_SUCCESS == result); // TODO not enough buffer to hold configuration descriptor - tusb_desc_configuration_t const * desc_config = (tusb_desc_configuration_t const*) _usbh_ctrl_buf; - uint16_t total_len; + uint8_t const * desc_config = _usbh_ctrl_buf; // Use offsetof to avoid pointer to the odd/misaligned address - memcpy(&total_len, (uint8_t*) desc_config + offsetof(tusb_desc_configuration_t, wTotalLength), 2); + uint16_t const total_len = tu_le16toh( tu_unaligned_read16(desc_config + offsetof(tusb_desc_configuration_t, wTotalLength)) ); TU_ASSERT(total_len <= CFG_TUH_ENUMERATION_BUFSIZE); -- cgit v1.3.1 From 6fcf4bee8c1540618b5d8d8709ef76cd2aa1c66f Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 18 Oct 2021 11:42:00 +0700 Subject: suppress null-dereference by usbh and lwip --- examples/device/net_lwip_webserver/Makefile | 3 ++ examples/host/cdc_msc_hid/Makefile | 3 +- examples/host/hid_controller/Makefile | 3 +- src/host/usbh.c | 46 +++++++++++++++++------------ 4 files changed, 34 insertions(+), 21 deletions(-) (limited to 'src/host') diff --git a/examples/device/net_lwip_webserver/Makefile b/examples/device/net_lwip_webserver/Makefile index c3e0d8899..5649a172a 100644 --- a/examples/device/net_lwip_webserver/Makefile +++ b/examples/device/net_lwip_webserver/Makefile @@ -7,6 +7,9 @@ CFLAGS += \ -DPBUF_POOL_SIZE=2 \ -DTCP_WND=2*TCP_MSS \ -DHTTPD_USE_CUSTOM_FSDATA=0 + +# suppress warning caused by lwip +CFLAGS += -Wno-error=null-dereference INC += \ src \ diff --git a/examples/host/cdc_msc_hid/Makefile b/examples/host/cdc_msc_hid/Makefile index 6a2b4d902..0ad9dd856 100644 --- a/examples/host/cdc_msc_hid/Makefile +++ b/examples/host/cdc_msc_hid/Makefile @@ -9,7 +9,8 @@ INC += \ EXAMPLE_SOURCE += $(wildcard src/*.c) SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) -CFLAGS += -Wno-error=cast-align +# TODO: suppress warning caused by host stack +CFLAGS += -Wno-error=cast-align -Wno-error=null-dereference # TinyUSB Host Stack source SRC_C += \ diff --git a/examples/host/hid_controller/Makefile b/examples/host/hid_controller/Makefile index 6f59faeee..2595ec4a7 100644 --- a/examples/host/hid_controller/Makefile +++ b/examples/host/hid_controller/Makefile @@ -12,7 +12,8 @@ EXAMPLE_SOURCE += \ SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) -CFLAGS += -Wno-error=cast-align +# TODO: suppress warning caused by host stack +CFLAGS += -Wno-error=cast-align -Wno-error=null-dereference # TinyUSB Host Stack source SRC_C += \ diff --git a/src/host/usbh.c b/src/host/usbh.c index 53e8b9715..a9c2c201f 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -53,13 +53,39 @@ // USBH-HCD common data structure //--------------------------------------------------------------------+ +// device0 struct must be strictly a subset of normal device struct +typedef struct +{ + // port + uint8_t rhport; + uint8_t hub_addr; + uint8_t hub_port; + uint8_t speed; + + volatile struct TU_ATTR_PACKED + { + uint8_t connected : 1; + uint8_t addressed : 1; + uint8_t configured : 1; + uint8_t suspended : 1; + }; +} usbh_dev0_t; + typedef struct { - //------------- port -------------// + // port uint8_t rhport; uint8_t hub_addr; uint8_t hub_port; uint8_t speed; + volatile struct TU_ATTR_PACKED + { + uint8_t connected : 1; + uint8_t addressed : 1; + uint8_t configured : 1; + uint8_t suspended : 1; + }; + //------------- device descriptor -------------// uint16_t vid; uint16_t pid; @@ -73,14 +99,6 @@ typedef struct { // uint8_t interface_count; // bNumInterfaces alias //------------- device -------------// - struct TU_ATTR_PACKED - { - uint8_t connected : 1; - uint8_t addressed : 1; - uint8_t configured : 1; - uint8_t suspended : 1; - }; - volatile uint8_t state; // device state, value from enum tusbh_device_state_t uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) @@ -103,16 +121,6 @@ typedef struct { } usbh_device_t; -typedef struct -{ - uint8_t rhport; - uint8_t hub_addr; - uint8_t hub_port; - uint8_t speed; - - volatile uint8_t connected; -} usbh_dev0_t; - //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF -- cgit v1.3.1