From 7de2971b4003838604c5a4944f6b1891dd77a65d Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 14 Dec 2024 11:35:04 +0000 Subject: [PATCH 1/7] target: Fixed all the function pointer casts used to set up the `priv_free` member of the target structure --- src/target/efm32.c | 2 +- src/target/kinetis.c | 2 +- src/target/nrf51.c | 2 +- src/target/nrf54l.c | 2 +- src/target/target_internal.h | 6 ++++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/target/efm32.c b/src/target/efm32.c index e2ae72dfa3d..83a40f3f761 100644 --- a/src/target/efm32.c +++ b/src/target/efm32.c @@ -954,7 +954,7 @@ bool efm32_aap_probe(adiv5_access_port_s *ap) adiv5_ap_ref(ap); t->priv = ap; - t->priv_free = (void *)adiv5_ap_unref; + t->priv_free = (priv_free_func)adiv5_ap_unref; /* Read status */ DEBUG_INFO("EFM32: AAP STATUS=%08" PRIx32 "\n", adiv5_ap_read(ap, AAP_STATUS)); diff --git a/src/target/kinetis.c b/src/target/kinetis.c index 896b22becaa..e1e6962548c 100644 --- a/src/target/kinetis.c +++ b/src/target/kinetis.c @@ -573,7 +573,7 @@ bool kinetis_mdm_probe(adiv5_access_port_s *ap) t->mass_erase = kinetis_mdm_mass_erase; adiv5_ap_ref(ap); t->priv = ap; - t->priv_free = (void *)adiv5_ap_unref; + t->priv_free = (priv_free_func)adiv5_ap_unref; t->driver = "Kinetis Recovery (MDM-AP)"; t->regs_size = 0; diff --git a/src/target/nrf51.c b/src/target/nrf51.c index b44ae88e019..7400254f57f 100644 --- a/src/target/nrf51.c +++ b/src/target/nrf51.c @@ -427,7 +427,7 @@ bool nrf51_ctrl_ap_probe(adiv5_access_port_s *ap) t->mass_erase = nrf51_ctrl_ap_mass_erase; adiv5_ap_ref(ap); t->priv = ap; - t->priv_free = (void *)adiv5_ap_unref; + t->priv_free = (priv_free_func)adiv5_ap_unref; adiv5_ap_read(ap, CTRL_AP_PROT_EN); const uint32_t status = adiv5_ap_read(ap, CTRL_AP_PROT_EN); diff --git a/src/target/nrf54l.c b/src/target/nrf54l.c index 283b5b1bd38..3d411d0a6b5 100644 --- a/src/target/nrf54l.c +++ b/src/target/nrf54l.c @@ -153,7 +153,7 @@ bool nrf54l_ctrl_ap_probe(adiv5_access_port_s *ap) target->mass_erase = nrf54l_ctrl_ap_mass_erase; adiv5_ap_ref(ap); target->priv = ap; - target->priv_free = (void *)adiv5_ap_unref; + target->priv_free = (priv_free_func)adiv5_ap_unref; const uint32_t status = adiv5_ap_read(ap, NRF54L_CTRL_AP_APPROTECT_STATUS); diff --git a/src/target/target_internal.h b/src/target/target_internal.h index f7755cc94ae..668afe322c3 100644 --- a/src/target/target_internal.h +++ b/src/target/target_internal.h @@ -80,7 +80,7 @@ struct target_flash { }; /* - * ¹the mass_erase method must not cause any side effects outside the scope/address space of the flash + * ¹the mass_erase method must not cause any side effects outside the scope/address space of the flash * consider using the target mass_erase method instead for such cases */ @@ -113,6 +113,8 @@ struct breakwatch { #define MAX_CMDLINE 81 +typedef void (*priv_free_func)(void *flash); + struct target { target_controller_s *tc; @@ -180,7 +182,7 @@ struct target { target_s *next; void *priv; - void (*priv_free)(void *); + priv_free_func priv_free; /* Target designer and ID / partno */ uint16_t designer_code; From 74d195ea17c73abf9caec64bcfd3f84dc81cbbca Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 14 Dec 2024 11:35:39 +0000 Subject: [PATCH 2/7] gdb_if: Fixed a format string pointer conversion issue --- src/platforms/hosted/gdb_if.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/hosted/gdb_if.c b/src/platforms/hosted/gdb_if.c index 16641de2269..43c5ca454e6 100644 --- a/src/platforms/hosted/gdb_if.c +++ b/src/platforms/hosted/gdb_if.c @@ -140,7 +140,7 @@ static sockaddr_storage_s sockaddr_prepare(const uint16_t port) addrinfo_s *results = NULL; int res = getaddrinfo(NULL, "0", &hints, &results); if (res || !results) { - DEBUG_WARN("getaddrinfo returned %d (errno = %d), results is %p\n", res, errno, results); + DEBUG_WARN("getaddrinfo returned %d (errno = %d), results is %p\n", res, errno, (void *)results); return (sockaddr_storage_s){AF_UNSPEC}; } From 6379d0a3f0ae8585d3a430bc11188c911b7a4e6c Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 14 Dec 2024 11:37:10 +0000 Subject: [PATCH 3/7] ch579: Fixed use of a C23 feature and some missing parentheses in the register bit definition macros --- src/target/ch579.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/target/ch579.c b/src/target/ch579.c index 1528c940d27..dd687886f46 100644 --- a/src/target/ch579.c +++ b/src/target/ch579.c @@ -92,10 +92,10 @@ #define CH579_CONST_ROM_CMD_PROGRAM_INFO 0x99U /* Flash Protect base value; upper bits must be set*/ -#define CH579_RB_ROM_WE_MUST_10 0b10000000U +#define CH579_RB_ROM_WE_MUST_10 (1U << 7U) /* Flash Protect Bitmasks */ -#define CH579_RB_ROM_CODE_WE 1U << 3U -#define CH579_RB_ROM_DATA_WE 1U << 2U +#define CH579_RB_ROM_CODE_WE (1U << 3U) +#define CH579_RB_ROM_DATA_WE (1U << 2U) /* Flash Protect Standard value */ #define CH579_RB_ROM_WRITE_ENABLE CH579_RB_ROM_WE_MUST_10 | CH579_RB_ROM_CODE_WE | CH579_RB_ROM_DATA_WE #define CH579_RB_ROM_WRITE_DISABLE CH579_RB_ROM_WE_MUST_10 From 3dce5c4eb24a91302bde07f430fdb4f6c69428be Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 14 Dec 2024 11:37:41 +0000 Subject: [PATCH 4/7] adi: Fixed there being an extra `;` where there shouldn't be one --- src/target/adi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/adi.c b/src/target/adi.c index a3c95380ea4..8ddbfacdbbf 100644 --- a/src/target/adi.c +++ b/src/target/adi.c @@ -253,7 +253,7 @@ static const char *adi_cid_class_string(const cid_class_e cid_class) default: return "Unknown component"; /* Noted as reserved in the spec */ } -}; +} #endif uint16_t adi_designer_from_pidr(const uint64_t pidr) From 15a904e6a3bb6e7d2b5cd21f05f0ad1513d1a9b6 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 14 Dec 2024 11:37:57 +0000 Subject: [PATCH 5/7] meson: Updated the warning level used by the project --- meson.build | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 96dffc0f6f8..52991cca169 100644 --- a/meson.build +++ b/meson.build @@ -38,8 +38,7 @@ project( 'c_std=c11', 'optimization=s', 'debug=true', - # 'warning_level=3', # TODO: Enable by default when all warnings are fixed - 'warning_level=2', + 'warning_level=3', 'werror=false', 'b_ndebug=if-release', ], From aa79837f41404482daad3e658d01a0e58c15abf3 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 17 Dec 2024 21:32:26 +0000 Subject: [PATCH 6/7] ctxlink/platform: Corrected a sscanf() format string to get the types to agree properly --- src/platforms/ctxlink/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platforms/ctxlink/platform.c b/src/platforms/ctxlink/platform.c index 6db2df39357..bae0466c3e5 100644 --- a/src/platforms/ctxlink/platform.c +++ b/src/platforms/ctxlink/platform.c @@ -107,7 +107,7 @@ bool platform_configure_uart(char *configuration_string) uint32_t stopBits; char parity; int count = sscanf( - configuration_string, "%" SCNd32 ",%" SCNd32 ",%c,%" SCNd32 "", &baudRate, &bits, &parity, &stopBits); + configuration_string, "%" SCNu32 ",%" SCNu32 ",%c,%" SCNu32 "", &baudRate, &bits, &parity, &stopBits); if (count == 4) { uint32_t parityValue; usart_set_baudrate(USBUSART, baudRate); From 86704be968af4a8aa16e01a5f409e04028819391 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Tue, 17 Dec 2024 21:43:44 +0000 Subject: [PATCH 7/7] stlinkv3/usb_f723: Removed some unnecessary casts on the callback function pointers which trigger UB --- src/platforms/stlinkv3/usb_f723.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platforms/stlinkv3/usb_f723.c b/src/platforms/stlinkv3/usb_f723.c index 22e11bab4e7..30d5644e594 100644 --- a/src/platforms/stlinkv3/usb_f723.c +++ b/src/platforms/stlinkv3/usb_f723.c @@ -208,7 +208,7 @@ static void stm32f723_ep_setup(usbd_device *usbd_dev, uint8_t addr, uint8_t type OTG_DIEPCTL0_SNAK | (type << 18) | OTG_DIEPCTL0_USBAEP | OTG_DIEPCTLX_SD0PID | (addr << 22) | max_size; if (callback) - usbd_dev->user_callback_ctr[addr][USB_TRANSACTION_IN] = (void *)callback; + usbd_dev->user_callback_ctr[addr][USB_TRANSACTION_IN] = callback; } if (!dir) { @@ -218,7 +218,7 @@ static void stm32f723_ep_setup(usbd_device *usbd_dev, uint8_t addr, uint8_t type (type << 18) | max_size; if (callback) - usbd_dev->user_callback_ctr[addr][USB_TRANSACTION_OUT] = (void *)callback; + usbd_dev->user_callback_ctr[addr][USB_TRANSACTION_OUT] = callback; } }