From 8097e3dde6645ff1ee63c588fa8949e61153aab5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 26 Mar 2025 10:52:04 -0500 Subject: [PATCH 1/3] Address -Wtype-limits diagnostics This fixes an unlikely problem with the USB host implementation on rp2350 that would not have detected failure to allocate a DMA channel. Together with #10186 this should give a clean build. As it is, this will error. --- main.c | 6 +++--- ports/raspberrypi/Makefile | 2 +- ports/raspberrypi/common-hal/usb_host/Port.c | 5 +++-- py/circuitpy_defns.mk | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index c9c7acb11f7b..0ea389635f40 100644 --- a/main.c +++ b/main.c @@ -131,9 +131,9 @@ static uint8_t *_allocate_memory(safe_mode_t safe_mode, const char *env_key, siz *final_size = default_size; #if CIRCUITPY_OS_GETENV if (safe_mode == SAFE_MODE_NONE) { - (void)common_hal_os_getenv_int(env_key, (mp_int_t *)final_size); - if (*final_size < 0) { - *final_size = default_size; + mp_int_t size; + if (common_hal_os_getenv_int(env_key, &size) == GETENV_OK && size > 0) { + *final_size = size; } } #endif diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index cb58e9035244..f531fca1663c 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -222,7 +222,7 @@ endif DISABLE_WARNINGS = -Wno-cast-align -CFLAGS += $(INC) -Wall -Werror -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes +CFLAGS += $(INC) -Wtype-limits -Wall -Werror -std=gnu11 -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes PICO_LDFLAGS = --specs=nosys.specs --specs=nano.specs diff --git a/ports/raspberrypi/common-hal/usb_host/Port.c b/ports/raspberrypi/common-hal/usb_host/Port.c index e350c288f71a..200c0bd2bf51 100644 --- a/ports/raspberrypi/common-hal/usb_host/Port.c +++ b/ports/raspberrypi/common-hal/usb_host/Port.c @@ -138,10 +138,11 @@ usb_host_port_obj_t *common_hal_usb_host_port_construct(const mcu_pin_obj_t *dp, } pio_cfg.pio_tx_num = get_usb_pio(); pio_cfg.pio_rx_num = pio_cfg.pio_tx_num; - pio_cfg.tx_ch = dma_claim_unused_channel(false); // DMA channel - if (pio_cfg.tx_ch < 0) { + int dma_ch = dma_claim_unused_channel(false); + if (dma_ch < 0) { mp_raise_RuntimeError(MP_ERROR_TEXT("All dma channels in use")); } + pio_cfg.tx_ch = dma_ch; self->base.type = &usb_host_port_type; self->dp = dp; diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 513f7d2d64d9..2e7bba09d01b 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -944,7 +944,7 @@ SRC_CIRCUITPY_COMMON = \ ifeq ($(CIRCUITPY_QRIO),1) SRC_CIRCUITPY_COMMON += lib/quirc/lib/decode.c lib/quirc/lib/identify.c lib/quirc/lib/quirc.c lib/quirc/lib/version_db.c -$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h +$(BUILD)/lib/quirc/lib/%.o: CFLAGS += -Wno-type-limits -Wno-shadow -Wno-sign-compare -include shared-module/qrio/quirc_alloc.h endif ifdef LD_TEMPLATE_FILE From 57638449d6d98b42409e4d3dcd63a47839302de1 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 26 Mar 2025 12:31:55 -0500 Subject: [PATCH 2/3] Fix EOF test for web workflow repl --- supervisor/shared/serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index bc57500ed7c3..94b429b6ab65 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -298,7 +298,7 @@ char serial_read(void) { #if CIRCUITPY_WEB_WORKFLOW if (websocket_available()) { - char c = websocket_read_char(); + int c = websocket_read_char(); if (c != -1) { return c; } From 4d56785e6166e39f0d9fe1c0359f8b0c457191e3 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 26 Mar 2025 12:34:47 -0500 Subject: [PATCH 3/3] remove impossible code for rangechecking of socket proto arg --- shared-bindings/socketpool/SocketPool.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c index e58b75ba9287..e139e3a077ab 100644 --- a/shared-bindings/socketpool/SocketPool.c +++ b/shared-bindings/socketpool/SocketPool.c @@ -103,10 +103,6 @@ static mp_obj_t socketpool_socketpool_socket(size_t n_args, const mp_obj_t *pos_ socketpool_socketpool_sock_t type = args[ARG_type].u_int; socketpool_socketpool_ipproto_t proto = args[ARG_proto].u_int; - if (proto < 0) { - proto = 0; - } - return common_hal_socketpool_socket(self, family, type, proto); } MP_DEFINE_CONST_FUN_OBJ_KW(socketpool_socketpool_socket_obj, 1, socketpool_socketpool_socket);