summaryrefslogtreecommitdiff
path: root/drivers/acpi/osl.c
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2022-01-12 19:31:48 +0100
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2022-01-25 18:44:00 +0100
commit2e433a94dab0246fee706d18aaecd67007ead404 (patch)
treeb4cab171f1629db6a816e22f9cf1af0051f781ee /drivers/acpi/osl.c
parente783362eb54cd99b2cac8b3a9aeac942e6f6ac07 (diff)
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>
Diffstat (limited to 'drivers/acpi/osl.c')
-rw-r--r--drivers/acpi/osl.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 45c5c0e45e33..7a70c4bfc23c 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -642,22 +642,24 @@ u64 acpi_os_get_timer(void)
(ACPI_100NSEC_PER_SEC / HZ);
}
-acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
+acpi_status acpi_os_read_port(acpi_io_address port, u32 *value, u32 width)
{
u32 dummy;
- if (!value)
+ if (value)
+ *value = 0;
+ else
value = &dummy;
- *value = 0;
if (width <= 8) {
- *(u8 *) value = inb(port);
+ *value = inb(port);
} else if (width <= 16) {
- *(u16 *) value = inw(port);
+ *value = inw(port);
} else if (width <= 32) {
- *(u32 *) value = inl(port);
+ *value = inl(port);
} else {
- BUG();
+ pr_debug("%s: Access width %d not supported\n", __func__, width);
+ return AE_BAD_PARAMETER;
}
return AE_OK;
@@ -674,7 +676,8 @@ acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
} else if (width <= 32) {
outl(value, port);
} else {
- BUG();
+ pr_debug("%s: Access width %d not supported\n", __func__, width);
+ return AE_BAD_PARAMETER;
}
return AE_OK;