linux/include/acpi
Rafael J. Wysocki 3757b94802 ACPI / hotplug: Fix concurrency issues and memory leaks
This changeset is aimed at fixing a few different but related
problems in the ACPI hotplug infrastructure.

First of all, since notify handlers may be run in parallel with
acpi_bus_scan(), acpi_bus_trim() and acpi_bus_hot_remove_device()
and some of them are installed for ACPI handles that have no struct
acpi_device objects attached (i.e. before those objects are created),
those notify handlers have to take acpi_scan_lock to prevent races
from taking place (e.g. a struct acpi_device is found to be present
for the given ACPI handle, but right after that it is removed by
acpi_bus_trim() running in parallel to the given notify handler).
Moreover, since some of them call acpi_bus_scan() and
acpi_bus_trim(), this leads to the conclusion that acpi_scan_lock
should be acquired by the callers of these two funtions rather by
these functions themselves.

For these reasons, make all notify handlers that can handle device
addition and eject events take acpi_scan_lock and remove the
acpi_scan_lock locking from acpi_bus_scan() and acpi_bus_trim().
Accordingly, update all of their users to make sure that they
are always called under acpi_scan_lock.

Furthermore, since eject operations are carried out asynchronously
with respect to the notify events that trigger them, with the help
of acpi_bus_hot_remove_device(), even if notify handlers take the
ACPI scan lock, it still is possible that, for example,
acpi_bus_trim() will run between acpi_bus_hot_remove_device() and
the notify handler that scheduled its execution and that
acpi_bus_trim() will remove the device node passed to
acpi_bus_hot_remove_device() for ejection.  In that case, the struct
acpi_device object obtained by acpi_bus_hot_remove_device() will be
invalid and not-so-funny things will ensue.  To protect agaist that,
make the users of acpi_bus_hot_remove_device() run get_device() on
ACPI device node objects that are about to be passed to it and make
acpi_bus_hot_remove_device() run put_device() on them and check if
their ACPI handles are not NULL (make acpi_device_unregister() clear
the device nodes' ACPI handles for that check to work).

Finally, observe that acpi_os_hotplug_execute() actually can fail,
in which case its caller ought to free memory allocated for the
context object to prevent leaks from happening.  It also needs to
run put_device() on the device node that it ran get_device() on
previously in that case.  Modify the code accordingly.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Yinghai Lu <yinghai@kernel.org>
2013-02-13 14:36:47 +01:00
..
platform ACPICA: Cleanup indentation to reduce differences between Linux and ACPICA. 2013-01-10 12:36:18 +01:00
acbuffer.h ACPICA: Add struct header support for _FDE, _GRT, _GTM, and _SRT names. 2012-09-21 00:26:17 -04:00
acconfig.h ACPICA: Source restructuring: split large files into 8 new files. 2013-01-11 13:08:51 +01:00
acexcep.h ACPICA: Remove extra spaces after periods within comments 2012-11-15 00:31:26 +01:00
acnames.h ACPICA: AcpiGetObjectInfo: Add support for ACPI 5 _SUB method 2012-11-15 00:31:30 +01:00
acoutput.h ACPICA: Cleanup ACPI_DEBUG_PRINT macros to fix potential build breakages. 2013-01-10 12:36:23 +01:00
acpi_bus.h ACPI / hotplug: Fix concurrency issues and memory leaks 2013-02-13 14:36:47 +01:00
acpi_drivers.h ACPI: Pass segment/bus to _PRT add/del so they don't depend on pci_bus 2012-11-05 15:54:22 -07:00
acpi_numa.h ACPI: Store SRAT table revision 2012-01-17 04:19:04 -05:00
acpi.h UAPI: (Scripted) Convert #include "..." to #include <path/...> in kernel system headers 2012-10-02 18:01:25 +01:00
acpiosxf.h ACPICA: Cleanup indentation to reduce differences between Linux and ACPICA. 2013-01-10 12:36:18 +01:00
acpixf.h ACPICA: Cleanup table handler naming conflicts. 2013-01-11 13:10:16 +01:00
acrestyp.h ACPICA: Resources: Split interrupt share/wake bits into two fields. 2013-01-10 12:36:22 +01:00
actbl1.h ACPICA: Cleanup updated comments. 2013-01-10 12:36:17 +01:00
actbl2.h ACPICA: iASL: Finish support for CSRT table. 2013-01-10 12:36:21 +01:00
actbl3.h ACPICA: iASL: Finish support for the TPM2 table. 2013-01-10 12:36:21 +01:00
actbl.h ACPICA: Cleanup indentation to reduce differences between Linux and ACPICA. 2013-01-10 12:36:18 +01:00
actypes.h ACPICA: Cleanup table handler naming conflicts. 2013-01-11 13:10:16 +01:00
apei.h module_param: make bool parameters really bool (drivers & misc) 2012-01-13 09:32:20 +10:30
button.h ACPI: make ACPI button funcs no-ops if not built in 2009-09-17 14:48:23 -07:00
hed.h ACPI Hardware Error Device (PNP0C33) support 2010-05-19 22:40:24 -04:00
pdc_intel.h ACPI: Enable bit 11 in _PDC to advertise hw coord 2009-02-07 00:41:14 -05:00
processor.h cpuidle / ACPI : move cpuidle_device field out of the acpi_processor_power structure 2012-09-17 23:01:56 +02:00
reboot.h
video.h i915: Fix opregion notifications 2011-07-13 11:19:47 -07:00