Skip to content

Commit dae68d7

Browse files
committed
PCI: hotplug: ACPI: Fix context refcounting in acpiphp_grab_context()
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 <[email protected]> Cc: 3.15+ <[email protected]> # 3.15+ Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 4877846 commit dae68d7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

drivers/pci/hotplug/acpiphp_glue.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,21 @@ static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev)
122122
struct acpiphp_context *context;
123123

124124
acpi_lock_hp_context();
125+
125126
context = acpiphp_get_context(adev);
126-
if (!context || context->func.parent->is_going_away) {
127-
acpi_unlock_hp_context();
128-
return NULL;
127+
if (!context)
128+
goto unlock;
129+
130+
if (context->func.parent->is_going_away) {
131+
acpiphp_put_context(context);
132+
context = NULL;
133+
goto unlock;
129134
}
135+
130136
get_bridge(context->func.parent);
131137
acpiphp_put_context(context);
138+
139+
unlock:
132140
acpi_unlock_hp_context();
133141
return context;
134142
}

0 commit comments

Comments
 (0)