From d78565bcdbee6e33153bccefe9b28492dac7f367 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Wed, 4 Feb 2026 09:20:24 -0600 Subject: [PATCH] bsps/shared: 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. --- bsps/shared/dev/flash/xnandpsu_flashdev.c | 8 ++++---- bsps/shared/dev/gpio/gpio-support.c | 2 +- bsps/shared/dev/nand/xnandpsu.c | 2 +- bsps/shared/dev/pci/pci_bus_count.c | 4 ++-- bsps/shared/dev/serial/console-polled.c | 2 +- bsps/shared/dev/serial/legacy-console.c | 6 +++--- bsps/shared/dev/serial/versal-uart.c | 4 ++-- bsps/shared/dev/serial/zynq-uart.c | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bsps/shared/dev/flash/xnandpsu_flashdev.c b/bsps/shared/dev/flash/xnandpsu_flashdev.c index cce1933b58..1bc2c4ba87 100644 --- a/bsps/shared/dev/flash/xnandpsu_flashdev.c +++ b/bsps/shared/dev/flash/xnandpsu_flashdev.c @@ -141,7 +141,7 @@ static int xnandpsu_erase_wrapper( } /* Perform erase operation. */ - for ( int i = 0; i < erase_count; i++ ) { + for ( uint64_t i = 0; i < erase_count; i++ ) { uint8_t sector_bad = 0; uint64_t block_start = start_offset + i * block_size; rv = xnandpsu_sector_health( flash, block_start, §or_bad ); @@ -246,7 +246,7 @@ static int xnandpsu_sector_info_by_offset( *sector_off = RTEMS_ALIGN_DOWN( search_off, nandpsu->Geometry.BlockSize ); *sector_size = nandpsu->Geometry.BlockSize; - if ( *sector_off > nandpsu->Geometry.DeviceSize ) { + if ( (uint64_t)*sector_off > nandpsu->Geometry.DeviceSize ) { return -EIO; } @@ -270,7 +270,7 @@ static int xnandpsu_sector_health( sector_off = RTEMS_ALIGN_DOWN( search_offset, nandpsu->Geometry.BlockSize ); - if ( sector_off > nandpsu->Geometry.DeviceSize ) { + if ( (uint64_t)sector_off > nandpsu->Geometry.DeviceSize ) { return -EIO; } @@ -422,7 +422,7 @@ static int xnandpsu_sector_mark_bad( rtems_flashdev *flash, off_t offset ) rtems_status_code sc; uint32_t BlockIndex; - if ( offset > nandpsu->Geometry.DeviceSize ) { + if ( (uint64_t)offset > nandpsu->Geometry.DeviceSize ) { return -EIO; } diff --git a/bsps/shared/dev/gpio/gpio-support.c b/bsps/shared/dev/gpio/gpio-support.c index ebb1fc0ff0..84d8b12909 100644 --- a/bsps/shared/dev/gpio/gpio-support.c +++ b/bsps/shared/dev/gpio/gpio-support.c @@ -1281,7 +1281,7 @@ int rtems_gpio_get_value(uint32_t pin_number) rv = rtems_gpio_bsp_get_value(bank, pin); - if ( rv == GPIO_INPUT_ERROR ) { + if ( rv == (uint32_t) GPIO_INPUT_ERROR ) { RELEASE_LOCK(gpio_bank_state[bank].lock); return -1; diff --git a/bsps/shared/dev/nand/xnandpsu.c b/bsps/shared/dev/nand/xnandpsu.c index 5a8d9e2cbd..5510abf0a3 100644 --- a/bsps/shared/dev/nand/xnandpsu.c +++ b/bsps/shared/dev/nand/xnandpsu.c @@ -1638,7 +1638,7 @@ s32 XNandPsu_Read(XNandPsu *InstancePtr, u64 Offset, u64 Length, u8 *DestBuf) (u32)LengthVar; } #ifdef __rtems__ - if (Page == InstancePtr->PartialDataPageIndex) { + if (Page == (uint32_t)InstancePtr->PartialDataPageIndex) { /* * This is a whole page read for the currently cached * page. It will not be taken care of below, so perform diff --git a/bsps/shared/dev/pci/pci_bus_count.c b/bsps/shared/dev/pci/pci_bus_count.c index 459f909376..3073ae8e9e 100644 --- a/bsps/shared/dev/pci/pci_bus_count.c +++ b/bsps/shared/dev/pci/pci_bus_count.c @@ -32,7 +32,7 @@ unsigned char pci_bus_count(void) for (device=0; device < PCI_MAX_DEVICES; device++) { pci_read_config_dword(bus, device, 0, PCI_VENDOR_ID, &vendor); - if ( vendor == -1 ) { + if ( vendor == (uint32_t)-1 ) { continue; } @@ -41,7 +41,7 @@ unsigned char pci_bus_count(void) for ( function=0; function < number_of_functions; function++ ) { pci_read_config_dword(bus, device, function, PCI_VENDOR_ID, &vendor); - if ( vendor == -1 ) { + if ( vendor == (uint32_t)-1 ) { continue; } diff --git a/bsps/shared/dev/serial/console-polled.c b/bsps/shared/dev/serial/console-polled.c index 5aa7e4ba93..c1c8fd3ef5 100644 --- a/bsps/shared/dev/serial/console-polled.c +++ b/bsps/shared/dev/serial/console-polled.c @@ -56,7 +56,7 @@ ssize_t console_write_support ( size_t len ) { - int nwrite = 0; + size_t nwrite = 0; const char *buf = bufarg; while (nwrite < len) { diff --git a/bsps/shared/dev/serial/legacy-console.c b/bsps/shared/dev/serial/legacy-console.c index 0ed4c32301..916230041c 100644 --- a/bsps/shared/dev/serial/legacy-console.c +++ b/bsps/shared/dev/serial/legacy-console.c @@ -100,7 +100,7 @@ console_tbl* console_find_console_entry( */ void console_initialize_data(void) { - int i; + uint32_t i; if ( Console_Port_Tbl ) return; @@ -140,8 +140,8 @@ void console_register_devices( size_t number_of_ports ) { - int old_number_of_ports; - int i; + int old_number_of_ports; + size_t i; /* * Initialize the console data elements diff --git a/bsps/shared/dev/serial/versal-uart.c b/bsps/shared/dev/serial/versal-uart.c index 96bca644c7..e702f64b87 100644 --- a/bsps/shared/dev/serial/versal-uart.c +++ b/bsps/shared/dev/serial/versal-uart.c @@ -90,7 +90,7 @@ static void versal_uart_interrupt(void *arg) if ((uartmis & (PL011_UARTI_RTI | PL011_UARTI_RXI)) != 0) { char buf[32]; - int c = 0; + size_t c = 0; while (c < sizeof(buf) && versal_uart_flags_clear(regs, PL011_UARTFR_RXFE)) { buf[c++] = (char) PL011_UARTDR_DATA_GET(regs->base.uartdr); @@ -254,7 +254,7 @@ static void versal_uart_write_support( ctx->transmitting = true; } #else - ssize_t i; + size_t i; for (i = 0; i < len; ++i) { arm_pl011_write_polled(base, buf[i]); } diff --git a/bsps/shared/dev/serial/zynq-uart.c b/bsps/shared/dev/serial/zynq-uart.c index 9228d48205..ebeb8e1a52 100644 --- a/bsps/shared/dev/serial/zynq-uart.c +++ b/bsps/shared/dev/serial/zynq-uart.c @@ -41,7 +41,7 @@ static void zynq_uart_interrupt(void *arg) if ((regs->irq_sts & ZYNQ_UART_RTRIG) != 0) { char buf[32]; - int c = 0; + size_t c = 0; regs->irq_sts = ZYNQ_UART_RTRIG; while (c < sizeof(buf) && (regs->channel_sts & ZYNQ_UART_CHANNEL_STS_REMPTY) == 0) {