From 6de3352acb29430e78abb2a728653a43c6274baf Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 3 Feb 2026 16:50:28 -0600 Subject: [PATCH] bsps/arm: Address -Wsign-compare warnings This warning occurs when comparing a signed variable to an unsigned one. This addresses warnings that only occurred on 64-bit targets. For the ones which only appeared on 64-bit targets, the cause was frequently a mismatch when comparing a combination off_t, ssize_t, and int. --- .../contrib/hwlib/src/hwmgr/alt_qspi.c | 8 ++++++++ bsps/arm/altera-cyclone-v/rtc/rtc.c | 10 +++++----- bsps/arm/beagle/i2c/bbb-i2c.c | 2 +- bsps/arm/csb336/console/uart.c | 2 +- bsps/arm/csb337/console/dbgu.c | 3 ++- bsps/arm/csb337/console/usart.c | 2 +- .../mcux-sdk/drivers/smartcard/fsl_smartcard_emvsim.c | 4 ++++ bsps/arm/imxrt/spi/imxrt-lpspi.c | 8 +++++++- bsps/arm/include/libcpu/omap3.h | 3 ++- bsps/arm/lm3s69xx/console/uart.c | 2 +- bsps/arm/lpc176x/can/can.c | 2 +- bsps/arm/lpc176x/include/bsp/can.h | 2 +- bsps/arm/raspberrypi/console/fbcons.c | 2 +- bsps/arm/raspberrypi/start/vc.c | 2 +- bsps/arm/shared/cp15/arm-cp15-set-ttb-entries.c | 4 ++-- bsps/arm/smdk2410/console/uart.c | 2 +- bsps/arm/smdk2410/smc/smc.c | 2 +- bsps/arm/stm32f4/console/usart.c | 2 +- bsps/arm/stm32h7/spi/spi-support.c | 4 ++-- 19 files changed, 43 insertions(+), 23 deletions(-) diff --git a/bsps/arm/altera-cyclone-v/contrib/hwlib/src/hwmgr/alt_qspi.c b/bsps/arm/altera-cyclone-v/contrib/hwlib/src/hwmgr/alt_qspi.c index 945d24732c..25ca6c941a 100644 --- a/bsps/arm/altera-cyclone-v/contrib/hwlib/src/hwmgr/alt_qspi.c +++ b/bsps/arm/altera-cyclone-v/contrib/hwlib/src/hwmgr/alt_qspi.c @@ -2044,7 +2044,11 @@ ALT_STATUS_CODE alt_qspi_erase_chip(void) uint32_t die_count = qspi_device_size / ALT_QSPI_N25Q_DIE_SIZE; +#ifdef __rtems__ + for (uint32_t i = 0; i < die_count; ++i) +#else for (int i = 0; i < die_count; ++i) +#endif { if (status != ALT_E_SUCCESS) { @@ -2161,7 +2165,11 @@ static bool is_pow_2(uint32_t n) static uint32_t log2u(uint32_t value) { uint32_t exp = 0; +#ifdef __rtems__ + while ((exp < 32) && (value != (1U << exp))) +#else while ((exp < 32) && (value != (1 << exp))) +#endif { ++exp; } diff --git a/bsps/arm/altera-cyclone-v/rtc/rtc.c b/bsps/arm/altera-cyclone-v/rtc/rtc.c index d3bf1a4b7b..d2589b9836 100644 --- a/bsps/arm/altera-cyclone-v/rtc/rtc.c +++ b/bsps/arm/altera-cyclone-v/rtc/rtc.c @@ -269,7 +269,7 @@ static rtems_status_code ds1339_read(uint8_t addr, void* buf, size_t size) if (sc == RTEMS_SUCCESSFUL) { rv = read(fd, buf, size); - if (rv != size) + if (rv != (ssize_t)size) sc = RTEMS_IO_ERROR; } @@ -294,7 +294,7 @@ static rtems_status_code ds1339_write(uint8_t addr, void* buf, size_t size) uint8_t local_buf[DS1339_MAX_WRITE_SIZE]; int write_size = size + 1; - assert(write_size <= DS1339_MAX_WRITE_SIZE); + assert(write_size <= (ssize_t)DS1339_MAX_WRITE_SIZE); local_buf[0] = addr; memcpy(&local_buf[1], buf, size); @@ -649,14 +649,14 @@ static rtems_status_code m41st87_read(uint8_t addr, void* buf, size_t size) if (sc == RTEMS_SUCCESSFUL) { rv = write(fd, &addr, sizeof(addr)); - if (rv != sizeof(addr)) + if (rv != (ssize_t)sizeof(addr)) sc = RTEMS_IO_ERROR; } if (sc == RTEMS_SUCCESSFUL) { rv = read(fd, buf, size); - if (rv != size) + if (rv != (ssize_t)size) sc = RTEMS_IO_ERROR; } @@ -681,7 +681,7 @@ static rtems_status_code m41st87_write(uint8_t addr, void* buf, size_t size) uint8_t local_buf[M41ST87_MAX_WRITE_SIZE]; int write_size = size + 1; - assert(write_size <= M41ST87_MAX_WRITE_SIZE); + assert(write_size <= (ssize_t)M41ST87_MAX_WRITE_SIZE); local_buf[0] = addr; memcpy(&local_buf[1], buf, size); diff --git a/bsps/arm/beagle/i2c/bbb-i2c.c b/bsps/arm/beagle/i2c/bbb-i2c.c index 4c5b1e9ec2..58b8784bfa 100644 --- a/bsps/arm/beagle/i2c/bbb-i2c.c +++ b/bsps/arm/beagle/i2c/bbb-i2c.c @@ -508,7 +508,7 @@ void beagle_i2c_init(phandle_t node) if (err < 0) { /* No path was provided in the device tree therefore use the default one */ snprintf(bus_path, PATH_LEN, "/dev/i2c-%d", unit); - } else if (err >= PATH_LEN) { + } else if ((size_t)err >= PATH_LEN) { /* Null terminate the string */ bus_path[PATH_LEN - 1] = 0; printk("i2c: bus path too long, trucated %s\n", bus_path); diff --git a/bsps/arm/csb336/console/uart.c b/bsps/arm/csb336/console/uart.c index da978f89bc..bfd5cb7078 100644 --- a/bsps/arm/csb336/console/uart.c +++ b/bsps/arm/csb336/console/uart.c @@ -315,7 +315,7 @@ static int imx_uart_poll_read(int minor) static ssize_t imx_uart_poll_write(int minor, const char *buf, size_t len) { - int i; + size_t i; for (i = 0; i < len; i++) { /* Wait for there to be room in the fifo */ while (!(imx_uart_data[minor].regs->sr2 & MC9328MXL_UART_SR2_TXDC)) { diff --git a/bsps/arm/csb337/console/dbgu.c b/bsps/arm/csb337/console/dbgu.c index b361209c66..65fe4bb3fd 100644 --- a/bsps/arm/csb337/console/dbgu.c +++ b/bsps/arm/csb337/console/dbgu.c @@ -142,7 +142,8 @@ static int dbgu_read(int minor) */ static ssize_t dbgu_write(int minor, const char *buf, size_t len) { - int i, x; + int x; + size_t i; char c; console_tbl *console_entry; at91rm9200_dbgu_regs_t *dbgu; diff --git a/bsps/arm/csb337/console/usart.c b/bsps/arm/csb337/console/usart.c index 20cd9916f2..29aade0c25 100644 --- a/bsps/arm/csb337/console/usart.c +++ b/bsps/arm/csb337/console/usart.c @@ -163,7 +163,7 @@ static void usart_write_polled(int minor, char c) static ssize_t usart_write_polled_support(int minor, const char *buf, size_t len) { at91rm9200_usart_regs_t *usart; - int nwrite=0; + size_t nwrite=0; /* * Verify the minor number diff --git a/bsps/arm/imxrt/mcux-sdk/drivers/smartcard/fsl_smartcard_emvsim.c b/bsps/arm/imxrt/mcux-sdk/drivers/smartcard/fsl_smartcard_emvsim.c index 61bca20b49..61515bb516 100644 --- a/bsps/arm/imxrt/mcux-sdk/drivers/smartcard/fsl_smartcard_emvsim.c +++ b/bsps/arm/imxrt/mcux-sdk/drivers/smartcard/fsl_smartcard_emvsim.c @@ -944,7 +944,11 @@ void SMARTCARD_EMVSIM_IRQHandler(EMVSIM_Type *base, smartcard_context_t *context /* To fifo will be written 2 or more bytes */ size_t getu_tail = (size_t)(base->TX_GETU > 0u); while (((context->txFifoEntryCount - (uint8_t)((base->TX_STATUS & EMVSIM_TX_STATUS_TX_CNT_MASK) >> +#ifdef __rtems__ + EMVSIM_TX_STATUS_TX_CNT_SHIFT)) > 0) && +#else EMVSIM_TX_STATUS_TX_CNT_SHIFT)) > 0u) && +#endif (context->xSize > getu_tail)) { /* Write data to fifo */ diff --git a/bsps/arm/imxrt/spi/imxrt-lpspi.c b/bsps/arm/imxrt/spi/imxrt-lpspi.c index ec61e8b7d3..6969b659ed 100644 --- a/bsps/arm/imxrt/spi/imxrt-lpspi.c +++ b/bsps/arm/imxrt/spi/imxrt-lpspi.c @@ -99,9 +99,15 @@ static void imxrt_lpspi_find_clockdivs( int best_sckdif; int best_prescale; +#ifdef __rtems__ + unsigned check_baud_hz; + unsigned check_sckdif; + unsigned check_prescale; +#else int check_baud_hz; int check_sckdif; int check_prescale; +#endif /* Start with slowest possible */ best_sckdif = max_sckdif; @@ -425,7 +431,7 @@ static int imxrt_lpspi_check_howmany( uint32_t max ) { - int i; + uint32_t i; if (max == 0) { return max; diff --git a/bsps/arm/include/libcpu/omap3.h b/bsps/arm/include/libcpu/omap3.h index ad90a23625..712f90dd72 100644 --- a/bsps/arm/include/libcpu/omap3.h +++ b/bsps/arm/include/libcpu/omap3.h @@ -87,7 +87,8 @@ #define OMAP3_INTR_ILR(base,m) \ (base + OMAP3_INTCPS_ILR0 + 0x4 * (m)) -#define OMAP3_INTR_SPURIOUSIRQ_MASK (0x1FFFFFF << 7) /* Spurious IRQ mask for SIR_IRQ */ +#define OMAP3_INTR_SPURIOUSIRQ_MASK \ + (uint32_t) (0x1FFFFFF << 7) /* Spurious IRQ mask for SIR_IRQ */ #define OMAP3_INTR_ACTIVEIRQ_MASK 0x7F /* Active IRQ mask for SIR_IRQ */ #define OMAP3_INTR_NEWIRQAGR 0x1 /* New IRQ Generation */ diff --git a/bsps/arm/lm3s69xx/console/uart.c b/bsps/arm/lm3s69xx/console/uart.c index 41301aa811..3dedec412b 100644 --- a/bsps/arm/lm3s69xx/console/uart.c +++ b/bsps/arm/lm3s69xx/console/uart.c @@ -141,7 +141,7 @@ static ssize_t write_support_polled( size_t n ) { - ssize_t i = 0; + size_t i = 0; for (i = 0; i < n; ++i) { write_polled(minor, s [i]); diff --git a/bsps/arm/lpc176x/can/can.c b/bsps/arm/lpc176x/can/can.c index b1d756ed86..ba3b49f408 100644 --- a/bsps/arm/lpc176x/can/can.c +++ b/bsps/arm/lpc176x/can/can.c @@ -526,7 +526,7 @@ rtems_status_code can_register_isr( rtems_status_code create_can_message( can_message *const msg, - const int _id, + const unsigned int _id, const char *const _data, const char _len ) diff --git a/bsps/arm/lpc176x/include/bsp/can.h b/bsps/arm/lpc176x/include/bsp/can.h index 395afdd14e..fcdf16a4a8 100644 --- a/bsps/arm/lpc176x/include/bsp/can.h +++ b/bsps/arm/lpc176x/include/bsp/can.h @@ -169,7 +169,7 @@ rtems_status_code can_register_isr( */ rtems_status_code create_can_message( can_message *const msg, - const int _id, + const unsigned int _id, const char *const _data, const char _len ); diff --git a/bsps/arm/raspberrypi/console/fbcons.c b/bsps/arm/raspberrypi/console/fbcons.c index 732eb6f0e1..7b16867d02 100644 --- a/bsps/arm/raspberrypi/console/fbcons.c +++ b/bsps/arm/raspberrypi/console/fbcons.c @@ -100,7 +100,7 @@ static void fbcons_write_support_polled( size_t len ) { - int nwrite = 0; + size_t nwrite = 0; /* * poll each byte in the string out of the port. diff --git a/bsps/arm/raspberrypi/start/vc.c b/bsps/arm/raspberrypi/start/vc.c index 1b0e397bd0..49bf6976ae 100644 --- a/bsps/arm/raspberrypi/start/vc.c +++ b/bsps/arm/raspberrypi/start/vc.c @@ -211,7 +211,7 @@ int bcm2835_mailbox_get_pitch( bcm2835_get_pitch_entries *_entries ) int bcm2835_mailbox_get_cmdline( bcm2835_get_cmdline_entries *_entries ) { - int i; + uint32_t i; struct BCM2835_MBOX_BUF_ALIGN_ATTRIBUTE { bcm2835_mbox_buf_hdr hdr; diff --git a/bsps/arm/shared/cp15/arm-cp15-set-ttb-entries.c b/bsps/arm/shared/cp15/arm-cp15-set-ttb-entries.c index 25ee8103e4..6471ab93ef 100644 --- a/bsps/arm/shared/cp15/arm-cp15-set-ttb-entries.c +++ b/bsps/arm/shared/cp15/arm-cp15-set-ttb-entries.c @@ -125,8 +125,8 @@ static uint32_t set_translation_table_entries( * Multiprocessing Extensions register format and the U (bit 30) * is 0. */ - #define MPIDR_MX_FMT (1 << 31) - #define MPIDR_UP (1 << 30) + #define MPIDR_MX_FMT (uint32_t)(1 << 31) + #define MPIDR_UP (uint32_t)(1 << 30) const uint32_t mpidr = arm_cp15_get_multiprocessor_affinity(); if ((mpidr & (MPIDR_MX_FMT | MPIDR_UP)) == MPIDR_MX_FMT) { arm_cp15_tlb_invalidate_entry_all_asids_inner_shareable(mva); diff --git a/bsps/arm/smdk2410/console/uart.c b/bsps/arm/smdk2410/console/uart.c index 8c9aaeb0b1..07f373a0b7 100644 --- a/bsps/arm/smdk2410/console/uart.c +++ b/bsps/arm/smdk2410/console/uart.c @@ -179,7 +179,7 @@ static int uart_read(int minor) */ static ssize_t uart_write(int minor, const char *buf, size_t len) { - int i; + size_t i; if (minor == 0) { for (i = 0; i < len; i++) { diff --git a/bsps/arm/smdk2410/smc/smc.c b/bsps/arm/smdk2410/smc/smc.c index 8124cfb1dd..dfd61a21c6 100644 --- a/bsps/arm/smdk2410/smc/smc.c +++ b/bsps/arm/smdk2410/smc/smc.c @@ -336,7 +336,7 @@ smc_read(rtems_blkdev_request *req) sg = req->bufs; for (i = 0; (remains > 0) && (i < req->bufnum); i++, sg++) { - int count = sg->length; + uint32_t count = sg->length; if (count > remains) count = remains; smc_read_page(sg->block,sg->buffer); diff --git a/bsps/arm/stm32f4/console/usart.c b/bsps/arm/stm32f4/console/usart.c index 7035112c52..3a8f3b1024 100644 --- a/bsps/arm/stm32f4/console/usart.c +++ b/bsps/arm/stm32f4/console/usart.c @@ -249,7 +249,7 @@ static ssize_t usart_write_support_polled( size_t n ) { - ssize_t i = 0; + size_t i = 0; for (i = 0; i < n; ++i) { usart_write_polled(minor, s [i]); diff --git a/bsps/arm/stm32h7/spi/spi-support.c b/bsps/arm/stm32h7/spi/spi-support.c index 0987d94a01..91799aeef4 100644 --- a/bsps/arm/stm32h7/spi/spi-support.c +++ b/bsps/arm/stm32h7/spi/spi-support.c @@ -555,7 +555,7 @@ static int stm32h7_spi_transfer( { stm32h7_spi_context *ctx = RTEMS_CONTAINER_OF(base, stm32h7_spi_context, bus); - for (int i = 0; i < msg_count; i++) { + for (uint32_t i = 0; i < msg_count; i++) { const spi_ioc_transfer *msg = &msgs[i]; if (stm32h7_spi_apply_premessage_settings(ctx, msg)) { @@ -718,7 +718,7 @@ static int stm32h7_register_spi_device( void stm32h7_register_spi_devices(void) { - int i; + size_t i; for (i = 0; i < (RTEMS_ARRAY_SIZE(stm32h7_spi_instances)); i++) { if (stm32h7_spi_instances[i] == NULL) {