Skip to content

Commit

Permalink
unsigned: fix loop variables
Browse files Browse the repository at this point in the history
When compiling with more alarms, signed vs unsigned comparison issues
are raised. Hence, fix them before actually enabling additional
checks.

Signed-off-by: Norbert Manthey <[email protected]>
  • Loading branch information
nmanthey authored and wipawel committed Aug 21, 2020
1 parent 074e6fe commit d81aa6f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions arch/x86/boot/multiboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void display_multiboot_mmap(void) {
return;
}

for (int i = 0; i < multiboot_mmap_num; i++) {
for (unsigned int i = 0; i < multiboot_mmap_num; i++) {
multiboot_memory_map_t *entry = &multiboot_mmap[i];

if (entry->type != MULTIBOOT_MEMORY_UNDEFINED) {
Expand All @@ -85,7 +85,7 @@ unsigned mbi_get_avail_memory_ranges_num(void) {
unsigned num = 0;

if (has_mbi_flag(MULTIBOOT_INFO_MEM_MAP)) {
for (int i = 0; i < multiboot_mmap_num; i++) {
for (unsigned int i = 0; i < multiboot_mmap_num; i++) {
multiboot_memory_map_t *entry = &multiboot_mmap[i];

if (entry->type == MULTIBOOT_MEMORY_AVAILABLE)
Expand All @@ -102,7 +102,7 @@ int mbi_get_avail_memory_range(unsigned index, addr_range_t *r) {
unsigned avail = 0;

if (has_mbi_flag(MULTIBOOT_INFO_MEM_MAP)) {
for (int i = 0; i < multiboot_mmap_num; i++) {
for (unsigned int i = 0; i < multiboot_mmap_num; i++) {
multiboot_memory_map_t *entry = &multiboot_mmap[i];

if (entry->type != MULTIBOOT_MEMORY_AVAILABLE)
Expand Down Expand Up @@ -135,7 +135,7 @@ int mbi_get_memory_range(paddr_t pa, addr_range_t *r) {
paddr_t _start, _end;

if (has_mbi_flag(MULTIBOOT_INFO_MEM_MAP)) {
for (int i = 0; i < multiboot_mmap_num; i++) {
for (unsigned int i = 0; i < multiboot_mmap_num; i++) {
multiboot_memory_map_t *entry = &multiboot_mmap[i];

_start = _paddr(entry->addr);
Expand Down
10 changes: 5 additions & 5 deletions common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static unsigned nr_cpus;
static inline uint8_t get_checksum(void *ptr, size_t len) {
uint8_t checksum = 0;

for (int i = 0; i < len; i++)
for (unsigned int i = 0; i < len; i++)
checksum += *((uint8_t *) ptr + i);

return checksum;
Expand Down Expand Up @@ -142,7 +142,7 @@ static inline xsdt_t *acpi_find_xsdt(const rsdp_rev2_t *rsdp) {
}

static void acpi_dump_tables(void) {
for (int i = 0; i < max_acpi_tables; i++) {
for (unsigned int i = 0; i < max_acpi_tables; i++) {
acpi_table_t *tab = acpi_tables[i];
acpi_table_hdr_t *hdr = &tab->header;

Expand Down Expand Up @@ -193,7 +193,7 @@ static unsigned process_madt_entries(void) {
}

acpi_table_t *acpi_find_table(uint32_t signature) {
for (int i = 0; i < max_acpi_tables; i++) {
for (unsigned int i = 0; i < max_acpi_tables; i++) {
acpi_table_t *tab = acpi_tables[i];

if (tab->header.signature == signature)
Expand All @@ -217,7 +217,7 @@ void init_acpi(void) {
if (rsdp->rev < 2) {
rsdt_t *rsdt = acpi_find_rsdt(rsdp);

for (int i = 0; i < ACPI_NR_TABLES(rsdt); i++) {
for (unsigned int i = 0; i < ACPI_NR_TABLES(rsdt); i++) {
acpi_table_t *tab = acpi_map_table(rsdt->entry[i]);

if (get_checksum(tab, tab->header.length) == 0x0)
Expand All @@ -227,7 +227,7 @@ void init_acpi(void) {
else {
xsdt_t *xsdt = acpi_find_xsdt((rsdp_rev2_t *) rsdp);

for (int i = 0; i < ACPI_NR_TABLES(xsdt); i++) {
for (unsigned int i = 0; i < ACPI_NR_TABLES(xsdt); i++) {
paddr_t tab_pa = _ul(xsdt->entry[i].high) << 32 | xsdt->entry[i].low;
acpi_table_t *tab = acpi_map_table(tab_pa);

Expand Down
2 changes: 1 addition & 1 deletion drivers/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static inline void write_vga_buffer(void) {
void vga_write(const char *buf, size_t len, vga_color_t color) {
static int row = 0, col = 0;

for (int i = 0; i < len; i++) {
for (unsigned int i = 0; i < len; i++) {
char c = buf[i];

/* Newline on LF or when columns limit is hit */
Expand Down
2 changes: 1 addition & 1 deletion mm/pmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void init_pmm(void) {
num = mbi_get_avail_memory_ranges_num();

/* Skip low memory range */
for (int i = 1; i < num; i++)
for (unsigned int i = 1; i < num; i++)
total_size += process_memory_range(i);

display_frames_count(total_size);
Expand Down
2 changes: 1 addition & 1 deletion smp/mptables.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static unsigned nr_cpus;
static inline uint8_t get_mp_checksum(void *ptr, size_t len) {
uint8_t checksum = 0;

for (int i = 0; i < len; i++)
for (unsigned int i = 0; i < len; i++)
checksum += *((uint8_t *) ptr + i);

return checksum;
Expand Down
2 changes: 1 addition & 1 deletion smp/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void smp_init(void) {

printk("Initializing SMP support (CPUs: %u)\n", nr_cpus);

for (int i = 0; i < nr_cpus; i++)
for (unsigned int i = 0; i < nr_cpus; i++)
boot_cpu(i);
}

Expand Down

0 comments on commit d81aa6f

Please sign in to comment.