Skip to content

Commit ba0b236

Browse files
committed
ACPI: x86: cmos_rtc: Clean up address space handler driver
Make multiple changes that do not alter functionality to the CMOS RTC ACPI address space handler driver, including the following: - Drop the unused .detach() callback from cmos_rtc_handler. - Rename acpi_cmos_rtc_attach_handler() to acpi_cmos_rtc_attach(). - Rearrange acpi_cmos_rtc_space_handler() to reduce the number of redundant checks and make white space follow the coding style. - Adjust an error message in acpi_install_cmos_rtc_space_handler() and make the white space follow the coding style. - Rearrange acpi_remove_cmos_rtc_space_handler() and adjust an error message in it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Link: https://patch.msgid.link/5094429.31r3eYUQgx@rafael.j.wysocki
1 parent 6de23f8 commit ba0b236

1 file changed

Lines changed: 32 additions & 29 deletions

File tree

drivers/acpi/x86/cmos_rtc.c

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,47 @@ static const struct acpi_device_id acpi_cmos_rtc_ids[] = {
2424
{}
2525
};
2626

27-
static acpi_status
28-
acpi_cmos_rtc_space_handler(u32 function, acpi_physical_address address,
29-
u32 bits, u64 *value64,
30-
void *handler_context, void *region_context)
27+
static acpi_status acpi_cmos_rtc_space_handler(u32 function,
28+
acpi_physical_address address,
29+
u32 bits, u64 *value64,
30+
void *handler_context,
31+
void *region_context)
3132
{
32-
int i;
33+
unsigned int i, bytes = DIV_ROUND_UP(bits, 8);
3334
u8 *value = (u8 *)value64;
3435

3536
if (address > 0xff || !value64)
3637
return AE_BAD_PARAMETER;
3738

38-
if (function != ACPI_WRITE && function != ACPI_READ)
39-
return AE_BAD_PARAMETER;
39+
guard(spinlock_irq)(&rtc_lock);
40+
41+
if (function == ACPI_WRITE) {
42+
for (i = 0; i < bytes; i++, address++, value++)
43+
CMOS_WRITE(*value, address);
4044

41-
spin_lock_irq(&rtc_lock);
45+
return AE_OK;
46+
}
4247

43-
for (i = 0; i < DIV_ROUND_UP(bits, 8); ++i, ++address, ++value)
44-
if (function == ACPI_READ)
48+
if (function == ACPI_READ) {
49+
for (i = 0; i < bytes; i++, address++, value++)
4550
*value = CMOS_READ(address);
46-
else
47-
CMOS_WRITE(*value, address);
4851

49-
spin_unlock_irq(&rtc_lock);
52+
return AE_OK;
53+
}
5054

51-
return AE_OK;
55+
return AE_BAD_PARAMETER;
5256
}
5357

5458
int acpi_install_cmos_rtc_space_handler(acpi_handle handle)
5559
{
5660
acpi_status status;
5761

5862
status = acpi_install_address_space_handler(handle,
59-
ACPI_ADR_SPACE_CMOS,
60-
&acpi_cmos_rtc_space_handler,
61-
NULL, NULL);
63+
ACPI_ADR_SPACE_CMOS,
64+
acpi_cmos_rtc_space_handler,
65+
NULL, NULL);
6266
if (ACPI_FAILURE(status)) {
63-
pr_err("Error installing CMOS-RTC region handler\n");
67+
pr_err("Failed to install CMOS-RTC address space handler\n");
6468
return -ENODEV;
6569
}
6670

@@ -70,26 +74,25 @@ EXPORT_SYMBOL_GPL(acpi_install_cmos_rtc_space_handler);
7074

7175
void acpi_remove_cmos_rtc_space_handler(acpi_handle handle)
7276
{
73-
if (ACPI_FAILURE(acpi_remove_address_space_handler(handle,
74-
ACPI_ADR_SPACE_CMOS, &acpi_cmos_rtc_space_handler)))
75-
pr_err("Error removing CMOS-RTC region handler\n");
77+
acpi_status status;
78+
79+
status = acpi_remove_address_space_handler(handle,
80+
ACPI_ADR_SPACE_CMOS,
81+
acpi_cmos_rtc_space_handler);
82+
if (ACPI_FAILURE(status))
83+
pr_err("Failed to remove CMOS-RTC address space handler\n");
7684
}
7785
EXPORT_SYMBOL_GPL(acpi_remove_cmos_rtc_space_handler);
7886

79-
static int acpi_cmos_rtc_attach_handler(struct acpi_device *adev, const struct acpi_device_id *id)
87+
static int acpi_cmos_rtc_attach(struct acpi_device *adev,
88+
const struct acpi_device_id *id)
8089
{
8190
return acpi_install_cmos_rtc_space_handler(adev->handle);
8291
}
8392

84-
static void acpi_cmos_rtc_detach_handler(struct acpi_device *adev)
85-
{
86-
acpi_remove_cmos_rtc_space_handler(adev->handle);
87-
}
88-
8993
static struct acpi_scan_handler cmos_rtc_handler = {
9094
.ids = acpi_cmos_rtc_ids,
91-
.attach = acpi_cmos_rtc_attach_handler,
92-
.detach = acpi_cmos_rtc_detach_handler,
95+
.attach = acpi_cmos_rtc_attach,
9396
};
9497

9598
void __init acpi_cmos_rtc_init(void)

0 commit comments

Comments
 (0)