Skip to content

Commit 2e433a9

Browse files
committed
ACPI: OSL: Fix and clean up acpi_os_read/write_port()
First, remove type casts that make acpi_os_read_port() only work on little endian and are generally not needed. Second, avoid clearing the memory pointed to by the value return pointer in acpi_os_read_port() if it is the dummy on the stack (in which case clearing it is not necessary). Finally, prevent both acpi_os_read_port() and acpi_os_write_port() from crashing the kernel when they receive an unsupported width value and make them print a debug message and return an error instead. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent e783362 commit 2e433a9

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

drivers/acpi/osl.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,22 +642,24 @@ u64 acpi_os_get_timer(void)
642642
(ACPI_100NSEC_PER_SEC / HZ);
643643
}
644644

645-
acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
645+
acpi_status acpi_os_read_port(acpi_io_address port, u32 *value, u32 width)
646646
{
647647
u32 dummy;
648648

649-
if (!value)
649+
if (value)
650+
*value = 0;
651+
else
650652
value = &dummy;
651653

652-
*value = 0;
653654
if (width <= 8) {
654-
*(u8 *) value = inb(port);
655+
*value = inb(port);
655656
} else if (width <= 16) {
656-
*(u16 *) value = inw(port);
657+
*value = inw(port);
657658
} else if (width <= 32) {
658-
*(u32 *) value = inl(port);
659+
*value = inl(port);
659660
} else {
660-
BUG();
661+
pr_debug("%s: Access width %d not supported\n", __func__, width);
662+
return AE_BAD_PARAMETER;
661663
}
662664

663665
return AE_OK;
@@ -674,7 +676,8 @@ acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
674676
} else if (width <= 32) {
675677
outl(value, port);
676678
} else {
677-
BUG();
679+
pr_debug("%s: Access width %d not supported\n", __func__, width);
680+
return AE_BAD_PARAMETER;
678681
}
679682

680683
return AE_OK;

0 commit comments

Comments
 (0)