ACPI / hotplug / PCI: lost acpiphp_put_context in acpiphp_grab_context()
PATCH 1/1 ACPI / hotplug / PCI: lost acpiphp_put_context in acpiphp_grab_context()
--- drivers/pci/hotplug/acpiphp_glue.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/pci/hotplug/acpiphp_glue.c +2 -0
@@ -124,6 +124,8 @@ 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) +acpiphp_put_context (context);acpi_unlock_hp_context ();return NULL ; }
Signature · 1 line
1.8.3.1
Rafael J. Wysocki
maintainerQuoted 2 lines · Vasily Averin
Fixes edf5bf34d408 ("ACPI / dock: Use callback pointers from devices' ACPI hotplug contexts")
Thanks for the fix ->
Quoted 10 lines
Signed-off-by Vasily Averin <[email protected]>--- drivers/pci/hotplug/acpiphp_glue.c | 2 ++ 1 file changed, 2 insertions(+)drivers/pci/hotplug/acpiphp_glue.c +0
-0
drivers/pci/hotplug/acpiphp_glue.c static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev) · line 128
Quoted 5 lines
drivers/pci/hotplug/acpiphp_glue.c +2
-0@@ -124,6 +124,8 @@ 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) +acpiphp_put_context (context);
-> but I'd prefer:
if (context && context->func.parent->is_going_away) {
acpiphp_put_context(context);
context = NULL;
}
if (!context) {drivers/pci/hotplug/acpiphp_glue.c static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev)
Quoted 4 lines
drivers/pci/hotplug/acpiphp_glue.c +0
-1acpi_unlock_hp_context ();return NULL ; } --
Thanks!
PATCH v2 1/1 ACPI / hotplug / PCI: lost acpiphp_put_context in acpiphp_grab_context()
v2: followed to rafael@'s proposal
--- drivers/pci/hotplug/acpiphp_glue.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/pci/hotplug/acpiphp_glue.c +5 -1
@@ -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 ; }
Signature · 1 line
2.17.1
Quoted 15 lines · CEST Vasily Averin
v2: followed to rafael@'s proposal
Fixes edf5bf34d408 ("ACPI / dock: Use callback pointers from devices' ACPI hotplug contexts")Signed-off-by Vasily Averin <[email protected]>--- drivers/pci/hotplug/acpiphp_glue.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/pci/hotplug/acpiphp_glue.c +0
-0@@ -123,7 +123,11 @@ static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev)acpi_lock_hp_context ();
drivers/pci/hotplug/acpiphp_glue.c static struct acpiphp_context *acpiphp_grab_context(struct acpi_device *adev) · line 133
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +5
-1context =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 <[email protected]>
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.
--- drivers/pci/hotplug/acpiphp_glue.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +11 -3
@@ -122,13 +122,21 @@ static struct acpiphp_context *acpiphp_gstruct 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; }
Quoted 9 lines · Rafael J. Wysocki
Quoted 3 lines · CEST Vasily Averin
v2: followed to rafael@'s proposal
Fixes edf5bf34d408 ("ACPI / dock: Use callback pointers from devices' ACPI hotplug contexts")Signed-off-by Vasily Averin <[email protected]>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):
Thank you,
however could you please tell me what do you think about following variant?
drivers/pci/hotplug/acpiphp_glue.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +8 -7
@@ -119,16 +119,17 @@ static inline void put_bridge(struct acpiphp_bridge *bridge)static struct acpiphp_context *acpiphp_grab_context (struct acpi_device *adev) { -struct acpiphp_context *context; +struct acpiphp_context *c, *context =NULL ;acpi_lock_hp_context (); - context =acpiphp_get_context (adev); -if (!context || context->func.parent->is_going_away) { -acpi_unlock_hp_context (); -return NULL ; + c =acpiphp_get_context (adev); +if (c) { +if (c->func.parent->is_going_away == false) { +get_bridge (c->func.parent); + context = c; + } +acpiphp_put_context (c); } -get_bridge (context->func.parent); -acpiphp_put_context (context);acpi_unlock_hp_context ();return context; }
Rafael J. Wysocki
maintainerQuoted 37 lines · Vasily Averin
Quoted 9 lines · Rafael J. Wysocki
Quoted 3 lines · CEST Vasily Averin
v2: followed to rafael@'s proposal
Fixes edf5bf34d408 ("ACPI / dock: Use callback pointers from devices' ACPI hotplug contexts")Signed-off-by Vasily Averin <[email protected]>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):
Thank you,
however could you please tell me what do you think about following variant?drivers/pci/hotplug/acpiphp_glue.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)drivers/pci/hotplug/acpiphp_glue.c +4
-5@@ -119,16 +119,17 @@ static inline void put_bridge(struct acpiphp_bridge *bridge)static struct acpiphp_context *acpiphp_grab_context (struct acpi_device *adev) { -struct acpiphp_context *context; +struct acpiphp_context *c, *context =NULL ;acpi_lock_hp_context (); - context =acpiphp_get_context (adev); -if (!context || context->func.parent->is_going_away) { -acpi_unlock_hp_context (); -return NULL ; + c =acpiphp_get_context (adev); +if (c) { +if (c->func.parent->is_going_away == false) {
drivers/pci/hotplug/acpiphp_glue.c static inline void put_bridge(struct acpiphp_bridge *bridge) · line 135
Quoted 10 lines
drivers/pci/hotplug/acpiphp_glue.c +4
-2+get_bridge (c->func.parent); + context = c; + } +acpiphp_put_context (c); } -get_bridge (context->func.parent); -acpiphp_put_context (context);acpi_unlock_hp_context ();return context; }
There are reasons to do it the way I want:
- The indentation level is minimum.
- The real purpose of this function is to get a parent bridge reference, so that needs to be the central piece of it rather than the checks for exceptional cases.
- The second local var is not necessary.
Thanks!