Skip to content

Commit

Permalink
PCI: hotplug: ACPI: Fix context refcounting in acpiphp_grab_context()
Browse files Browse the repository at this point in the history
If context is not NULL in acpiphp_grab_context(), but the
is_going_away flag is set for the device's parent, the reference
counter of the context needs to be decremented before returning
NULL or the context will never be freed, so make that happen.

Fixes: edf5bf3 ("ACPI / dock: Use callback pointers from devices' ACPI hotplug contexts")
Reported-by: Vasily Averin <vvs@virtuozzo.com>
Cc: 3.15+ <stable@vger.kernel.org> # 3.15+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Rafael J. Wysocki committed Jun 26, 2020
1 parent 4877846 commit dae68d7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/pci/hotplug/acpiphp_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,21 @@ static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev)
struct acpiphp_context *context;

acpi_lock_hp_context();

context = acpiphp_get_context(adev);
if (!context || context->func.parent->is_going_away) {
acpi_unlock_hp_context();
return NULL;
if (!context)
goto unlock;

if (context->func.parent->is_going_away) {
acpiphp_put_context(context);
context = NULL;
goto unlock;
}

get_bridge(context->func.parent);
acpiphp_put_context(context);

unlock:
acpi_unlock_hp_context();
return context;
}
Expand Down

0 comments on commit dae68d7

Please sign in to comment.