Re: [PATCH v2] ACPI / hotplug / PCI: lost acpiphp_put_context in acpiphp_grab_context()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday, June 23, 2020 1:17:43 AM CEST Vasily Averin wrote:
> v2: followed to rafael@'s proposal
> Fixes: edf5bf34d408 ("ACPI / dock: Use callback pointers from devices' ACPI hotplug contexts")
> Signed-off-by: Vasily Averin <vvs@xxxxxxxxxxxxx>
> ---
>  drivers/pci/hotplug/acpiphp_glue.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
> index b4c92cee13f8..a0923a65e636 100644
> --- a/drivers/pci/hotplug/acpiphp_glue.c
> +++ b/drivers/pci/hotplug/acpiphp_glue.c
> @@ -123,7 +123,11 @@ static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev)
>  
>  	acpi_lock_hp_context();
>  	context = acpiphp_get_context(adev);
> -	if (!context || context->func.parent->is_going_away) {
> +	if (context && context->func.parent->is_going_away) {
> +		acpiphp_put_context(context);
> +		context = NULL;
> +	}
> +	if (!context) {
>  		acpi_unlock_hp_context();
>  		return NULL;
>  	}
> 

Thanks for following my suggestion, but it occurred to me that it could still be
done in a better way.

So instead of the above I'd prefer to apply the following change (added PCI and Bjorn
for visibility):

---
From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Subject: [PATCH] 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: edf5bf34d408 ("ACPI / dock: Use callback pointers from devices' ACPI hotplug contexts")
Reported-by: Vasily Averin <vvs@xxxxxxxxxxxxx>
Cc: 3.15+ <stable@xxxxxxxxxxxxxxx> # 3.15+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
---
 drivers/pci/hotplug/acpiphp_glue.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Index: linux-pm/drivers/pci/hotplug/acpiphp_glue.c
===================================================================
--- linux-pm.orig/drivers/pci/hotplug/acpiphp_glue.c
+++ linux-pm/drivers/pci/hotplug/acpiphp_glue.c
@@ -122,13 +122,21 @@ static struct acpiphp_context *acpiphp_g
 	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;
 }







[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux