From ecde3003e5205a283b46b931c729a2aecab64ba1 Mon Sep 17 00:00:00 2001 From: Vasiliy Kulikov Date: Wed, 22 May 2013 14:59:11 +0200 Subject: ACPI / EC: access user space with get_user()/put_user() User space pointer may not be dereferenced. Use get_user()/put_user() instead and check their return codes. Signed-off-by: Vasiliy Kulikov Signed-off-by: Thomas Renninger Signed-off-by: Jiri Slaby Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c index 7586544..4e7b798 100644 --- a/drivers/acpi/ec_sys.c +++ b/drivers/acpi/ec_sys.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "internal.h" MODULE_AUTHOR("Thomas Renninger "); @@ -34,7 +35,6 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf, * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; */ unsigned int size = EC_SPACE_SIZE; - u8 *data = (u8 *) buf; loff_t init_off = *off; int err = 0; @@ -47,9 +47,15 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf, size = count; while (size) { - err = ec_read(*off, &data[*off - init_off]); + u8 byte_read; + err = ec_read(*off, &byte_read); if (err) return err; + if (put_user(byte_read, buf + *off - init_off)) { + if (*off - init_off) + return *off - init_off; /* partial read */ + return -EFAULT; + } *off += 1; size--; } @@ -65,7 +71,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf, unsigned int size = count; loff_t init_off = *off; - u8 *data = (u8 *) buf; int err = 0; if (*off >= EC_SPACE_SIZE) @@ -76,7 +81,12 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf, } while (size) { - u8 byte_write = data[*off - init_off]; + u8 byte_write; + if (get_user(byte_write, buf + *off - init_off)) { + if (*off - init_off) + return *off - init_off; /* partial write */ + return -EFAULT; + } err = ec_write(*off, byte_write); if (err) return err; -- cgit v0.10.2 From c7d9ca90aa9497f0b6e301ec67c52dd4b57a7852 Mon Sep 17 00:00:00 2001 From: Jeff Wu Date: Wed, 29 May 2013 06:31:30 +0000 Subject: ACPI: add _STA evaluation at do_acpi_find_child() Once do_acpi_find_child() has found the first matching handle, it makes the acpi_get_child() loop stop and return that handle. On some platforms, though, there are multiple devices with the same value of "_ADR" in the same namespace scope, and if one of them is enabled, the others will be disabled. For example: Address : 0x1FFFF ; path : SB_PCI0.SATA.DEV0 Address : 0x1FFFF ; path : SB_PCI0.SATA.DEV1 Address : 0x1FFFF ; path : SB_PCI0.SATA.DEV2 If DEV0 and DEV1 are disabled and DEV2 is enabled, the handle of DEV2 should be returned, but actually the function always returns the handle of DEV0. To address that issue, make do_acpi_find_child() evaluate _STA to check the device status. If a matching device object exists, but is disabled, acpi_get_child() will continue to walk the namespace in the hope of finding an enabled one. If one is found, its handle will be returned, but otherwise the function will return the handle of the disabled object found before (in case it is enabled going forward). [rjw: Changelog] Signed-off-by: Jeff Wu Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c index 40a84cc..51ca764 100644 --- a/drivers/acpi/glue.c +++ b/drivers/acpi/glue.c @@ -81,13 +81,15 @@ static struct acpi_bus_type *acpi_get_bus_type(struct device *dev) static acpi_status do_acpi_find_child(acpi_handle handle, u32 lvl_not_used, void *addr_p, void **ret_p) { - unsigned long long addr; + unsigned long long addr, sta; acpi_status status; status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL, &addr); if (ACPI_SUCCESS(status) && addr == *((u64 *)addr_p)) { *ret_p = handle; - return AE_CTRL_TERMINATE; + status = acpi_bus_get_status_handle(handle, &sta); + if (ACPI_SUCCESS(status) && (sta & ACPI_STA_DEVICE_ENABLED)) + return AE_CTRL_TERMINATE; } return AE_OK; } -- cgit v0.10.2 From 0f4c65478d2ac03296415a5bdac1ead3e24cfc5b Mon Sep 17 00:00:00 2001 From: Nicholas Mazzuca Date: Wed, 8 May 2013 23:11:15 +0000 Subject: ACPI / battery: Make sure all spaces are in correct places Add or remove spaces that give errors or warnings from checkpatch.pl. Signed-off-by: Nicholas Mazzuca Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index e710045..082b4dd 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -425,7 +425,7 @@ static int acpi_battery_get_info(struct acpi_battery *battery) { int result = -EFAULT; acpi_status status = 0; - char *name = test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags)? + char *name = test_bit(ACPI_BATTERY_XINFO_PRESENT, &battery->flags) ? "_BIX" : "_BIF"; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; @@ -661,11 +661,11 @@ static void find_battery(const struct dmi_header *dm, void *private) static void acpi_battery_quirks(struct acpi_battery *battery) { if (test_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags)) - return ; + return; - if (battery->full_charge_capacity == 100 && - battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN && - battery->capacity_now >=0 && battery->capacity_now <= 100) { + if (battery->full_charge_capacity == 100 && + battery->rate_now == ACPI_BATTERY_VALUE_UNKNOWN && + battery->capacity_now >= 0 && battery->capacity_now <= 100) { set_bit(ACPI_BATTERY_QUIRK_PERCENTAGE_CAPACITY, &battery->flags); battery->full_charge_capacity = battery->design_capacity; battery->capacity_now = (battery->capacity_now * @@ -673,7 +673,7 @@ static void acpi_battery_quirks(struct acpi_battery *battery) } if (test_bit(ACPI_BATTERY_QUIRK_THINKPAD_MAH, &battery->flags)) - return ; + return; if (battery->power_unit && dmi_name_in_vendors("LENOVO")) { const char *s; @@ -761,7 +761,7 @@ static int acpi_battery_print_info(struct seq_file *seq, int result) goto end; seq_printf(seq, "present: %s\n", - acpi_battery_present(battery)?"yes":"no"); + acpi_battery_present(battery) ? "yes" : "no"); if (!acpi_battery_present(battery)) goto end; if (battery->design_capacity == ACPI_BATTERY_VALUE_UNKNOWN) @@ -817,12 +817,12 @@ static int acpi_battery_print_state(struct seq_file *seq, int result) goto end; seq_printf(seq, "present: %s\n", - acpi_battery_present(battery)?"yes":"no"); + acpi_battery_present(battery) ? "yes" : "no"); if (!acpi_battery_present(battery)) goto end; seq_printf(seq, "capacity state: %s\n", - (battery->state & 0x04)?"critical":"ok"); + (battery->state & 0x04) ? "critical" : "ok"); if ((battery->state & 0x01) && (battery->state & 0x02)) seq_printf(seq, "charging state: charging/discharging\n"); -- cgit v0.10.2 From 6a8c0af6e2d6c472517959b66c96900151c9cb5b Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 3 Jun 2013 18:20:24 +0000 Subject: ACPI: Remove useless initializers These local variables are all initialized at their first use, so there's no point in initializing them earlier. Signed-off-by: Bjorn Helgaas Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 292de3c..a5bb33b 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -91,8 +91,7 @@ static struct dmi_system_id dsdt_dmi_table[] __initdata = { int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device) { - acpi_status status = AE_OK; - + acpi_status status; if (!device) return -EINVAL; @@ -162,7 +161,7 @@ EXPORT_SYMBOL(acpi_bus_private_data_handler); int acpi_bus_get_private_data(acpi_handle handle, void **data) { - acpi_status status = AE_OK; + acpi_status status; if (!*data) return -EINVAL; @@ -361,7 +360,7 @@ extern int event_is_open; int acpi_bus_generate_proc_event4(const char *device_class, const char *bus_id, u8 type, int data) { struct acpi_bus_event *event; - unsigned long flags = 0; + unsigned long flags; /* drop event on the floor if no one's listening */ if (!event_is_open) @@ -400,7 +399,7 @@ EXPORT_SYMBOL(acpi_bus_generate_proc_event); int acpi_bus_receive_event(struct acpi_bus_event *event) { - unsigned long flags = 0; + unsigned long flags; struct acpi_bus_event *entry = NULL; DECLARE_WAITQUEUE(wait, current); @@ -593,7 +592,7 @@ static void acpi_bus_notify(acpi_handle handle, u32 type, void *data) static int __init acpi_bus_init_irq(void) { - acpi_status status = AE_OK; + acpi_status status; union acpi_object arg = { ACPI_TYPE_INTEGER }; struct acpi_object_list arg_list = { 1, &arg }; char *message = NULL; @@ -640,7 +639,7 @@ u8 acpi_gbl_permanent_mmap; void __init acpi_early_init(void) { - acpi_status status = AE_OK; + acpi_status status; if (acpi_disabled) return; @@ -714,8 +713,8 @@ void __init acpi_early_init(void) static int __init acpi_bus_init(void) { - int result = 0; - acpi_status status = AE_OK; + int result; + acpi_status status; extern acpi_status acpi_os_initialize1(void); acpi_os_initialize1(); -- cgit v0.10.2 From 358b4b35c8fa97a83c4d476cbd0830205504d798 Mon Sep 17 00:00:00 2001 From: Toshi Kani Date: Tue, 4 Jun 2013 21:56:25 +0000 Subject: ACPI: Remove unused flags in acpi_device_flags suprise_removal_ok and performance_manageable in struct acpi_device_flags are not used by any code. So, remove them. Signed-off-by: Toshi Kani Signed-off-by: Rafael J. Wysocki diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h index 636c59f..b790607 100644 --- a/include/acpi/acpi_bus.h +++ b/include/acpi/acpi_bus.h @@ -163,12 +163,10 @@ struct acpi_device_flags { u32 dynamic_status:1; u32 removable:1; u32 ejectable:1; - u32 suprise_removal_ok:1; u32 power_manageable:1; - u32 performance_manageable:1; u32 eject_pending:1; u32 match_driver:1; - u32 reserved:24; + u32 reserved:26; }; /* File System */ -- cgit v0.10.2 From 2fa97feb4406c546b52e35b6b6c50cb8f63425d2 Mon Sep 17 00:00:00 2001 From: Lan Tianyu Date: Wed, 5 Jun 2013 02:27:50 +0000 Subject: ACPI: Add CMOS RTC Operation Region handler support On HP Folio 13-2000, the BIOS defines a CMOS RTC Operation Region and the EC's _REG methord accesses that region. Thus an appropriate address space handler must be registered for that region before the EC driver is loaded. Introduce a mechanism for adding CMOS RTC address space handlers. Register an ACPI scan handler for CMOS RTC devices such that, when a device of that kind is detected during an ACPI namespace scan, a common CMOS RTC operation region address space handler will be installed for it. References: https://bugzilla.kernel.org/show_bug.cgi?id=54621 Reported-and-tested-by: Stefan Nagy Signed-off-by: Lan Tianyu Cc: 3.9+ Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile index 536562c..97c949a 100644 --- a/drivers/acpi/Makefile +++ b/drivers/acpi/Makefile @@ -43,6 +43,7 @@ acpi-y += acpi_platform.o acpi-y += power.o acpi-y += event.o acpi-y += sysfs.o +acpi-$(CONFIG_X86) += acpi_cmos_rtc.o acpi-$(CONFIG_DEBUG_FS) += debugfs.o acpi-$(CONFIG_ACPI_NUMA) += numa.o acpi-$(CONFIG_ACPI_PROCFS_POWER) += cm_sbs.o diff --git a/drivers/acpi/acpi_cmos_rtc.c b/drivers/acpi/acpi_cmos_rtc.c new file mode 100644 index 0000000..84190ed --- /dev/null +++ b/drivers/acpi/acpi_cmos_rtc.c @@ -0,0 +1,92 @@ +/* + * ACPI support for CMOS RTC Address Space access + * + * Copyright (C) 2013, Intel Corporation + * Authors: Lan Tianyu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include + +#include "internal.h" + +#define PREFIX "ACPI: " + +ACPI_MODULE_NAME("cmos rtc"); + +static const struct acpi_device_id acpi_cmos_rtc_ids[] = { + { "PNP0B00" }, + { "PNP0B01" }, + { "PNP0B02" }, + {} +}; + +static acpi_status +acpi_cmos_rtc_space_handler(u32 function, acpi_physical_address address, + u32 bits, u64 *value64, + void *handler_context, void *region_context) +{ + int i; + u8 *value = (u8 *)&value64; + + if (address > 0xff || !value64) + return AE_BAD_PARAMETER; + + if (function != ACPI_WRITE && function != ACPI_READ) + return AE_BAD_PARAMETER; + + spin_lock_irq(&rtc_lock); + + for (i = 0; i < DIV_ROUND_UP(bits, 8); ++i, ++address, ++value) + if (function == ACPI_READ) + *value = CMOS_READ(address); + else + CMOS_WRITE(*value, address); + + spin_unlock_irq(&rtc_lock); + + return AE_OK; +} + +static int acpi_install_cmos_rtc_space_handler(struct acpi_device *adev, + const struct acpi_device_id *id) +{ + acpi_status status; + + status = acpi_install_address_space_handler(adev->handle, + ACPI_ADR_SPACE_CMOS, + &acpi_cmos_rtc_space_handler, + NULL, NULL); + if (ACPI_FAILURE(status)) { + pr_err(PREFIX "Error installing CMOS-RTC region handler\n"); + return -ENODEV; + } + + return 0; +} + +static void acpi_remove_cmos_rtc_space_handler(struct acpi_device *adev) +{ + if (ACPI_FAILURE(acpi_remove_address_space_handler(adev->handle, + ACPI_ADR_SPACE_CMOS, &acpi_cmos_rtc_space_handler))) + pr_err(PREFIX "Error removing CMOS-RTC region handler\n"); +} + +static struct acpi_scan_handler cmos_rtc_handler = { + .ids = acpi_cmos_rtc_ids, + .attach = acpi_install_cmos_rtc_space_handler, + .detach = acpi_remove_cmos_rtc_space_handler, +}; + +void __init acpi_cmos_rtc_init(void) +{ + acpi_scan_add_handler(&cmos_rtc_handler); +} diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 297cbf4..4163d4b 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -45,6 +45,11 @@ void acpi_memory_hotplug_init(void); #else static inline void acpi_memory_hotplug_init(void) {} #endif +#ifdef CONFIG_X86 +void acpi_cmos_rtc_init(void); +#else +static inline void acpi_cmos_rtc_init(void) {} +#endif void acpi_sysfs_add_hotplug_profile(struct acpi_hotplug_profile *hotplug, const char *name); diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index b14ac46..a514be2 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -2040,6 +2040,7 @@ int __init acpi_scan_init(void) acpi_pci_link_init(); acpi_platform_init(); acpi_lpss_init(); + acpi_cmos_rtc_init(); acpi_container_init(); acpi_memory_hotplug_init(); -- cgit v0.10.2 From eff9a4b62b14cf0d9913e3caf1f26f8b7a6105c9 Mon Sep 17 00:00:00 2001 From: Lan Tianyu Date: Wed, 5 Jun 2013 02:27:51 +0000 Subject: ACPI / EC: Add HP Folio 13 to ec_dmi_table in order to skip DSDT scan HP Folio 13's BIOS defines CMOS RTC Operation Region and the EC's _REG method will access that region. To allow the CMOS RTC region handler to be installed before the EC _REG method is first invoked, add ec_skip_dsdt_scan() as HP Folio 13's callback to ec_dmi_table. References: https://bugzilla.kernel.org/show_bug.cgi?id=54621 Reported-and-tested-by: Stefan Nagy Signed-off-by: Lan Tianyu Cc: 3.9+ Signed-off-by: Rafael J. Wysocki diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index edc0081..80403c1 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -983,6 +983,10 @@ static struct dmi_system_id __initdata ec_dmi_table[] = { ec_enlarge_storm_threshold, "CLEVO hardware", { DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."), DMI_MATCH(DMI_PRODUCT_NAME, "M720T/M730T"),}, NULL}, + { + ec_skip_dsdt_scan, "HP Folio 13", { + DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), + DMI_MATCH(DMI_PRODUCT_NAME, "HP Folio 13"),}, NULL}, {}, }; -- cgit v0.10.2