* [PATCH] ACPI / bus: Move duplicate code to a separate new function
@ 2015-08-01 0:39 Rafael J. Wysocki
2015-08-03 9:48 ` Mika Westerberg
2015-08-03 14:58 ` Hanjun Guo
0 siblings, 2 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2015-08-01 0:39 UTC (permalink / raw)
To: Mika Westerberg, ACPI Devel Maling List
Cc: Linux Kernel Mailing List, Andy Shevchenko
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
After merging commit 712e960f0ee9 (ACPI / PM: Attach ACPI power
domain only once) with commit 1dcc3d3362b0 (ACPI / bus: Move ACPI
bus type registration) there is some duplicate code in
acpi_device_is_first_physical_node() and acpi_companion_match()
that can be moved to a separate routine and called from both
places.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
On top of linux-pm.git/linux-next.
---
drivers/acpi/bus.c | 51 ++++++++++++++++++++++-----------------------------
1 file changed, 22 insertions(+), 29 deletions(-)
Index: linux-pm/drivers/acpi/bus.c
===================================================================
--- linux-pm.orig/drivers/acpi/bus.c
+++ linux-pm/drivers/acpi/bus.c
@@ -482,6 +482,26 @@ static void acpi_device_remove_notify_ha
Device Matching
-------------------------------------------------------------------------- */
+static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev,
+ const struct device *dev)
+{
+ struct mutex *physical_node_lock = &adev->physical_node_lock;
+
+ mutex_lock(physical_node_lock);
+ if (list_empty(&adev->physical_node_list)) {
+ adev = NULL;
+ } else {
+ const struct acpi_device_physical_node *node;
+
+ node = list_first_entry(&adev->physical_node_list,
+ struct acpi_device_physical_node, node);
+ if (node->dev != dev)
+ adev = NULL;
+ }
+ mutex_unlock(physical_node_lock);
+ return adev;
+}
+
/**
* acpi_device_is_first_physical_node - Is given dev first physical node
* @adev: ACPI companion device
@@ -496,19 +516,7 @@ static void acpi_device_remove_notify_ha
bool acpi_device_is_first_physical_node(struct acpi_device *adev,
const struct device *dev)
{
- bool ret = false;
-
- mutex_lock(&adev->physical_node_lock);
- if (!list_empty(&adev->physical_node_list)) {
- const struct acpi_device_physical_node *node;
-
- node = list_first_entry(&adev->physical_node_list,
- struct acpi_device_physical_node, node);
- ret = node->dev == dev;
- }
- mutex_unlock(&adev->physical_node_lock);
-
- return ret;
+ return !!acpi_primary_dev_companion(adev, dev);
}
/*
@@ -535,7 +543,6 @@ bool acpi_device_is_first_physical_node(
struct acpi_device *acpi_companion_match(const struct device *dev)
{
struct acpi_device *adev;
- struct mutex *physical_node_lock;
adev = ACPI_COMPANION(dev);
if (!adev)
@@ -544,21 +551,7 @@ struct acpi_device *acpi_companion_match
if (list_empty(&adev->pnp.ids))
return NULL;
- physical_node_lock = &adev->physical_node_lock;
- mutex_lock(physical_node_lock);
- if (list_empty(&adev->physical_node_list)) {
- adev = NULL;
- } else {
- const struct acpi_device_physical_node *node;
-
- node = list_first_entry(&adev->physical_node_list,
- struct acpi_device_physical_node, node);
- if (node->dev != dev)
- adev = NULL;
- }
- mutex_unlock(physical_node_lock);
-
- return adev;
+ return acpi_primary_dev_companion(adev, dev);
}
/**
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ACPI / bus: Move duplicate code to a separate new function
2015-08-01 0:39 [PATCH] ACPI / bus: Move duplicate code to a separate new function Rafael J. Wysocki
@ 2015-08-03 9:48 ` Mika Westerberg
2015-08-03 14:58 ` Hanjun Guo
1 sibling, 0 replies; 3+ messages in thread
From: Mika Westerberg @ 2015-08-03 9:48 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: ACPI Devel Maling List, Linux Kernel Mailing List,
Andy Shevchenko
On Sat, Aug 01, 2015 at 02:39:43AM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> After merging commit 712e960f0ee9 (ACPI / PM: Attach ACPI power
> domain only once) with commit 1dcc3d3362b0 (ACPI / bus: Move ACPI
> bus type registration) there is some duplicate code in
> acpi_device_is_first_physical_node() and acpi_companion_match()
> that can be moved to a separate routine and called from both
> places.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ACPI / bus: Move duplicate code to a separate new function
2015-08-01 0:39 [PATCH] ACPI / bus: Move duplicate code to a separate new function Rafael J. Wysocki
2015-08-03 9:48 ` Mika Westerberg
@ 2015-08-03 14:58 ` Hanjun Guo
1 sibling, 0 replies; 3+ messages in thread
From: Hanjun Guo @ 2015-08-03 14:58 UTC (permalink / raw)
To: Rafael J. Wysocki, Mika Westerberg, ACPI Devel Maling List
Cc: Linux Kernel Mailing List, Andy Shevchenko
On 08/01/2015 08:39 AM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> After merging commit 712e960f0ee9 (ACPI / PM: Attach ACPI power
> domain only once) with commit 1dcc3d3362b0 (ACPI / bus: Move ACPI
> bus type registration) there is some duplicate code in
> acpi_device_is_first_physical_node() and acpi_companion_match()
> that can be moved to a separate routine and called from both
> places.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>
> On top of linux-pm.git/linux-next.
>
> ---
> drivers/acpi/bus.c | 51 ++++++++++++++++++++++-----------------------------
> 1 file changed, 22 insertions(+), 29 deletions(-)
>
> Index: linux-pm/drivers/acpi/bus.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/bus.c
> +++ linux-pm/drivers/acpi/bus.c
> @@ -482,6 +482,26 @@ static void acpi_device_remove_notify_ha
> Device Matching
> -------------------------------------------------------------------------- */
>
> +static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev,
> + const struct device *dev)
> +{
> + struct mutex *physical_node_lock = &adev->physical_node_lock;
> +
> + mutex_lock(physical_node_lock);
> + if (list_empty(&adev->physical_node_list)) {
> + adev = NULL;
> + } else {
> + const struct acpi_device_physical_node *node;
> +
> + node = list_first_entry(&adev->physical_node_list,
> + struct acpi_device_physical_node, node);
> + if (node->dev != dev)
> + adev = NULL;
> + }
> + mutex_unlock(physical_node_lock);
> + return adev;
> +}
> +
> /**
> * acpi_device_is_first_physical_node - Is given dev first physical node
> * @adev: ACPI companion device
> @@ -496,19 +516,7 @@ static void acpi_device_remove_notify_ha
> bool acpi_device_is_first_physical_node(struct acpi_device *adev,
> const struct device *dev)
> {
> - bool ret = false;
> -
> - mutex_lock(&adev->physical_node_lock);
> - if (!list_empty(&adev->physical_node_list)) {
> - const struct acpi_device_physical_node *node;
> -
> - node = list_first_entry(&adev->physical_node_list,
> - struct acpi_device_physical_node, node);
> - ret = node->dev == dev;
> - }
> - mutex_unlock(&adev->physical_node_lock);
> -
> - return ret;
> + return !!acpi_primary_dev_companion(adev, dev);
> }
>
> /*
> @@ -535,7 +543,6 @@ bool acpi_device_is_first_physical_node(
> struct acpi_device *acpi_companion_match(const struct device *dev)
> {
> struct acpi_device *adev;
> - struct mutex *physical_node_lock;
>
> adev = ACPI_COMPANION(dev);
> if (!adev)
> @@ -544,21 +551,7 @@ struct acpi_device *acpi_companion_match
> if (list_empty(&adev->pnp.ids))
> return NULL;
>
> - physical_node_lock = &adev->physical_node_lock;
> - mutex_lock(physical_node_lock);
> - if (list_empty(&adev->physical_node_list)) {
> - adev = NULL;
> - } else {
> - const struct acpi_device_physical_node *node;
> -
> - node = list_first_entry(&adev->physical_node_list,
> - struct acpi_device_physical_node, node);
> - if (node->dev != dev)
> - adev = NULL;
> - }
> - mutex_unlock(physical_node_lock);
> -
> - return adev;
> + return acpi_primary_dev_companion(adev, dev);
> }
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
Thanks
Hanjun
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-08-03 14:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-01 0:39 [PATCH] ACPI / bus: Move duplicate code to a separate new function Rafael J. Wysocki
2015-08-03 9:48 ` Mika Westerberg
2015-08-03 14:58 ` Hanjun Guo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).