From: Adrian Bunk This patch fixes an obvious use-after-free introduced by commit 837012ede14a8fc088be3682c964da7fc6af026b. Spotted by the Coverity checker. Signed-off-by: Adrian Bunk Cc: Alexey Starikovskiy Cc: Len Brown Cc: Michal Piotrowski Signed-off-by: Andrew Morton --- drivers/acpi/ec.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff -puN drivers/acpi/ec.c~acpi_ec_remove-fix-use-after-free drivers/acpi/ec.c --- a/drivers/acpi/ec.c~acpi_ec_remove-fix-use-after-free +++ a/drivers/acpi/ec.c @@ -734,14 +734,14 @@ static int acpi_ec_add(struct acpi_devic static int acpi_ec_remove(struct acpi_device *device, int type) { struct acpi_ec *ec; - struct acpi_ec_query_handler *handler; + struct acpi_ec_query_handler *handler, *tmp; if (!device) return -EINVAL; ec = acpi_driver_data(device); mutex_lock(&ec->lock); - list_for_each_entry(handler, &ec->list, node) { + list_for_each_entry_safe(handler, tmp, &ec->list, node) { list_del(&handler->node); kfree(handler); } _