Skip to content

Commit dbdb08b

Browse files
committed
x86: misc fixes
fix various issues found by clangd-static-analyzer
1 parent 829f7b1 commit dbdb08b

File tree

8 files changed

+33
-35
lines changed

8 files changed

+33
-35
lines changed

hal/x86_uart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int uart_init(uint32_t bitrate, uint8_t data, char parity, uint8_t stop)
142142

143143
mode = 0;
144144
mode |= data;
145-
mode |= (stop << 2);
145+
mode |= (stops << 2);
146146
mode |= (parity_bits << 3);
147147
write_reg(X86_UART_LCR, mode);
148148

src/boot_x86_fsp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ static int fsp_silicon_init(struct fsp_info_header *fsp_info, uint8_t *fsp_s_bas
501501
memcpy(silicon_init_parameter, fsp_s_base + fsp_info->CfgRegionOffset,
502502
FSP_S_PARAM_SIZE);
503503
status = fsp_machine_update_s_parameters(silicon_init_parameter);
504+
if (status != 0)
505+
panic();
504506
SiliconInit = (silicon_init_cb)(fsp_s_base + fsp_info->FspSiliconInitEntryOffset);
505507

506508
#if defined(WOLFBOOT_DUMP_FSP_UPD)

src/elf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb)
8888
/* Load class and endianess */
8989
is_elf32 = (h32->ident[4] == ELF_CLASS_32);
9090
is_le = (h32->ident[5] == ELF_ENDIAN_LITTLE);
91+
(void)is_le;
9192

9293
/* Verify this is an executable */
9394
if (GET_H16(type) != ELF_HET_EXEC) {

src/x86/ahci.c

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ int init_sata_controller(uint32_t bus, uint32_t dev, uint32_t fun)
171171
uint32_t ahci_enable(uint32_t bus, uint32_t dev, uint32_t fun)
172172
{
173173
uint16_t reg16;
174-
uint32_t iobar;
175174
uint32_t reg;
176175
uint32_t bar;
177176

@@ -180,8 +179,6 @@ uint32_t ahci_enable(uint32_t bus, uint32_t dev, uint32_t fun)
180179

181180
bar = pci_config_read32(bus, dev, fun, AHCI_ABAR_OFFSET);
182181
AHCI_DEBUG_PRINTF("PCI BAR: %08x\r\n", bar);
183-
iobar = pci_config_read32(bus, dev, fun, AHCI_AIDPBA_OFFSET);
184-
AHCI_DEBUG_PRINTF("PCI I/O space: %08x\r\n", iobar);
185182

186183
reg |= PCI_COMMAND_BUS_MASTER;
187184
reg |= PCI_COMMAND_MEM_SPACE;
@@ -197,29 +194,6 @@ uint32_t ahci_enable(uint32_t bus, uint32_t dev, uint32_t fun)
197194
return bar;
198195
}
199196

200-
/**
201-
* @brief Dumps the status of the specified AHCI port.
202-
*
203-
* This function dumps the status of the AHCI port with the given index.
204-
* It prints the status of various port registers for debugging purposes.
205-
*
206-
* @param base The AHCI Base Address Register (ABAR) for accessing AHCI registers.
207-
* @param i The index of the AHCI port to dump status for.
208-
*/
209-
void ahci_dump_port(uint32_t base, int i)
210-
{
211-
uint32_t cmd, ci, is, tfd, serr, ssst;
212-
213-
cmd = mmio_read32(AHCI_PxCMD(base, i));
214-
ci = mmio_read32(AHCI_PxCI(base, i));
215-
is = mmio_read32(AHCI_PxIS(base, i));
216-
tfd = mmio_read32(AHCI_PxTFD(base, i));
217-
serr = mmio_read32(AHCI_PxSERR(base, i));
218-
ssst = mmio_read32(AHCI_PxSSTS(base, i));
219-
AHCI_DEBUG_PRINTF("%d: cmd:0x%x ci:0x%x is: 0x%x tfd: 0x%x serr: 0x%x ssst: 0x%x\r\n",
220-
i, cmd, ci, is, tfd, serr, ssst);
221-
}
222-
223197
#ifdef WOLFBOOT_ATA_DISK_LOCK
224198
#ifdef WOLFBOOT_ATA_DISK_LOCK_PASSWORD
225199
static int sata_get_unlock_secret(uint8_t *secret, int *secret_size)
@@ -362,7 +336,7 @@ static int sata_get_unlock_secret(uint8_t *secret, int *secret_size)
362336
#error "implement get_tpm_policy "
363337
#endif
364338

365-
if (policy_size > TPM_MAX_POLICY_SIZE)
339+
if (policy_size > TPM_MAX_POLICY_SIZE || ret != 0)
366340
return -1;
367341

368342
memcpy(policy, pol, policy_size);
@@ -464,15 +438,21 @@ int sata_unlock_disk(int drv, int freeze)
464438
}
465439
r = ata_identify_device(drv);
466440
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
441+
if (r != 0)
442+
return -1;
467443
ata_st = ata_security_get_state(drv);
468444
wolfBoot_printf("ATA: State SEC%d\r\n", ata_st);
469445
}
470446
else if (ata_st == ATA_SEC4) {
471447
AHCI_DEBUG_PRINTF("ATA identify: calling device unlock\r\n", r);
472448
r = ata_security_unlock_device(drv, (char*)secret, 0);
473449
AHCI_DEBUG_PRINTF("ATA device unlock: returned %d\r\n", r);
450+
if (r != 0)
451+
return -1;
474452
r = ata_identify_device(drv);
475453
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
454+
if (r != 0)
455+
return -1;
476456
ata_st = ata_security_get_state(drv);
477457
if (ata_st == ATA_SEC5) {
478458
if (freeze) {
@@ -487,6 +467,8 @@ int sata_unlock_disk(int drv, int freeze)
487467
}
488468
r = ata_identify_device(drv);
489469
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
470+
if (r != 0)
471+
return -1;
490472
}
491473
}
492474
ata_st = ata_security_get_state(drv);
@@ -583,6 +565,7 @@ void sata_enable(uint32_t base)
583565

584566
cap = mmio_read32(AHCI_HBA_CAP(base));
585567
n_ports = (cap & 0x1F) + 1;
568+
(void)n_ports;
586569
sata_only = (cap & AHCI_CAP_SAM);
587570
cap_sud = (cap & AHCI_CAP_SSS);
588571

@@ -601,8 +584,8 @@ void sata_enable(uint32_t base)
601584
if ((ports_impl & (1 << i)) != 0) {
602585
uint32_t reg;
603586
uint32_t ssts = mmio_read32(AHCI_PxSSTS(base, i));
604-
uint8_t ipm = (ssts >> 8) & 0xFF;
605587
uint8_t det = ssts & 0x0F;
588+
uint8_t ipm;
606589
volatile struct hba_cmd_header *hdr;
607590

608591

@@ -736,6 +719,7 @@ void sata_enable(uint32_t base)
736719
AHCI_DEBUG_PRINTF("ATA%d associated to AHCI port %d\r\n",
737720
drv, i);
738721
r = ata_identify_device(drv);
722+
(void)r;
739723
AHCI_DEBUG_PRINTF("ATA identify: returned %d\r\n", r);
740724
}
741725
} else {

src/x86/ata.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ int ata_identify_device(int drv)
601601
if (slot < 0)
602602
return slot;
603603

604+
s_locked = s_frozen = s_enabled = 0;
604605
cmd = (struct hba_cmd_header *)(uintptr_t)ata->clb_port;
605606
cmd += slot;
606607

@@ -612,6 +613,7 @@ int ata_identify_device(int drv)
612613
ret = exec_cmd_slot(drv, slot);
613614
if (ret == 0) {
614615
uint16_t *id_buf = (uint16_t *)buffer;
616+
(void)id_buf;
615617
uint16_t cmd_set_supported;
616618
uint16_t sec_status;
617619
ATA_DEBUG_PRINTF("Device identified\r\n");
@@ -663,7 +665,6 @@ int ata_identify_device(int drv)
663665
}
664666
if (sec_status & (1 << 0)) {
665667
ATA_DEBUG_PRINTF("Security: supported\r\n");
666-
s_supported = 1;
667668
}
668669
if (!s_enabled && !s_frozen)
669670
ata->sec = ATA_SEC1;
@@ -697,6 +698,8 @@ static int ata_drive_read_sector(int drv, uint64_t start, uint32_t count,
697698
struct fis_reg_h2d *cmdfis;
698699
int i;
699700
int slot = prepare_cmd_h2d_slot(drv, buf, count << ata->sector_size_shift, 0);
701+
if (slot < 0)
702+
return -1;
700703
cmd = (struct hba_cmd_header *)(uintptr_t)ata->clb_port;
701704
cmd += slot;
702705

@@ -727,6 +730,8 @@ static int ata_drive_write_sector(int drv, uint64_t start, uint32_t count,
727730
uint8_t *buf_ptr;
728731
int i;
729732
int slot = prepare_cmd_h2d_slot(drv, buf, count << ata->sector_size_shift, 1);
733+
if (slot < 0)
734+
return -1;
730735
cmd = (struct hba_cmd_header *)(uintptr_t)ata->clb_port;
731736
cmd += slot;
732737
tbl = (struct hba_cmd_table *)(uintptr_t)cmd->ctba;
@@ -848,6 +853,9 @@ int ata_drive_write(int drv, uint64_t start, uint32_t size,
848853
sect_start = start >> ata->sector_size_shift;
849854
sect_off = start - (sect_start << ata->sector_size_shift);
850855

856+
if (size == 0)
857+
return 0;
858+
851859
if (sect_off > 0) {
852860
uint32_t len = MAX_SECTOR_SIZE - sect_off;
853861
if (len > size)
@@ -861,6 +869,7 @@ int ata_drive_write(int drv, uint64_t start, uint32_t size,
861869
buffer_off += len;
862870
sect_start++;
863871
}
872+
count = 0;
864873
if (size > 0)
865874
count = size >> ata->sector_size_shift;
866875
if (count > 0) {

src/x86/exceptions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static struct idt_descriptor idt_descriptor;
7676
"call common_exception_handler\r\n" \
7777
"iretq\r\n" \
7878
: \
79-
: ""(X)); \
79+
: "Z"(X)); \
8080
}
8181

8282
__attribute__((used)) static void common_exception_handler(uint64_t vector_number)
@@ -144,7 +144,7 @@ static void __attribute__((__naked__)) timer_handler() {
144144
"sti\r\n"
145145
"mov %0, %%eax\r\n"
146146
"movl $0, (%%eax)\r\n"
147-
"iretq\r\n"::""(LAPIC_EOI));
147+
"iretq\r\n"::"i"((uint32_t)LAPIC_EOI));
148148
}
149149

150150
static void setup_apic_timer()

src/x86/gpt.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,13 @@ int disk_open(int drv)
234234
uint64_t address = ptable.start_array * SECTOR_SIZE +
235235
i * ptable.array_sz;
236236
r = ata_drive_read(drv, address, ptable.array_sz, (void *)&pa);
237+
if (r < 0)
238+
return -1;
237239
if (pa.type[0] != 0 || pa.type[1] != 0) {
238240
uint64_t size;
239241
uint32_t part_count;
240242
if (pa.first > pa.last) {
241-
wolfBoot_printf("Bad geometry for partition %d\r\n", part_count);
243+
wolfBoot_printf("Bad geometry for partition %d\r\n", i);
242244
break;
243245
}
244246
size = (1 + pa.last - pa.first) * SECTOR_SIZE;

src/x86/tgl_fsp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,8 @@ static int tgl_setup_lpc_decode(uint32_t address, uint32_t length,
990990

991991
reg = PCI_ESPI_LGIR1 + range * 4;
992992
/* setup up decoding in eSPI - generic I/O range 0*/
993-
pci_config_write32(PCI_ESPI_BUS, PCI_ESPI_DEV, PCI_ESPI_FUN, PCI_ESPI_LGIR1, val);
993+
pci_config_write32(PCI_ESPI_BUS, PCI_ESPI_DEV, PCI_ESPI_FUN,
994+
reg, val);
994995

995996
return 0;
996997
}
@@ -1523,7 +1524,6 @@ static void setup_ece1200()
15231524

15241525
io_write8(ECE1200_INDEX, 0x55); /* conf mode */
15251526
io_write8(ECE1200_INDEX, 0x36);
1526-
reg = io_read8(ECE1200_DATA);
15271527

15281528
io_write8(ECE1200_INDEX, 0x07);
15291529
io_write8(ECE1200_DATA, 0x01);

0 commit comments

Comments
 (0)