Skip to contentSkip to conversation

acpi_table: Fix coverity defect in acpi_write_spcr

PATCH In review Patrick Rudolph 2 participants 2 messages Oct 30, 2024 – Nov 2, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 acpi_table: Fix coverity defect in acpi_write_spcr

Fix "Integer handling issues (SIGN_EXTENSION)" in newly added code:
Cast serial_info.reg_offset to u64 to prevent an integer overflow when shifted too many bits to the left. Currently this never happens as the shift is supposed to be less than 4.

---
 lib/acpi/acpi_table.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/acpi/acpi_table.c +3 -3
index 6473d95c10..150f75027a 100644
@@ -420,7 +420,7 @@ int acpi_write_dbg2_pci_uart(struct acpi_ctx *ctx, struct udevice *dev,
 static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry)
 {
 	struct serial_device_info serial_info = {0};
-	ulong serial_address, serial_offset;
+	u64 serial_address, serial_offset;
 	struct acpi_table_header *header;
 	struct acpi_spcr *spcr;
 	struct udevice *dev;
@@ -473,7 +473,7 @@ static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry
 	}
 
 	serial_width = serial_info.reg_width * 8;
-	serial_offset = serial_info.reg_offset << serial_info.reg_shift;
+	serial_offset = ((u64)serial_info.reg_offset) << serial_info.reg_shift;
 	serial_address = serial_info.addr + serial_offset;
 
 	/* Encode register access size */
@@ -495,7 +495,7 @@ static int acpi_write_spcr(struct acpi_ctx *ctx, const struct acpi_writer *entry
 		break;
 	}
 
-	debug("UART type %u @ %lx\n", spcr->interface_type, serial_address);
+	debug("UART type %u @ %llx\n", spcr->interface_type, serial_address);
 
 	/* Fill GAS */
 	spcr->serial_port.space_id = space_id;
Signature · 1 line
2.46.2
#1 lore raw
Quoted 6 lines · Patrick Rudolph

Fix "Integer handling issues (SIGN_EXTENSION)" in newly added code:
Cast serial_info.reg_offset to u64 to prevent an integer overflow when shifted too many bits to the left. Currently this never happens as the shift is supposed to be less than 4.

Applied to local tree/v2-tidy-test-dir, thanks!

Signature · 1 line
Tom