Skip to content

Commit

Permalink
ACPI / bus: Move duplicate code to a separate new function
Browse files Browse the repository at this point in the history
After merging commit 712e960 (ACPI / PM: Attach ACPI power
domain only once) with commit 1dcc3d3 (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>
Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org>
  • Loading branch information
Rafael J. Wysocki committed Aug 6, 2015
1 parent 50ba224 commit e91a398
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions drivers/acpi/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,26 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device)
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
Expand All @@ -500,19 +520,7 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device)
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);
}

/*
Expand All @@ -539,7 +547,6 @@ bool acpi_device_is_first_physical_node(struct acpi_device *adev,
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)
Expand All @@ -548,21 +555,7 @@ struct acpi_device *acpi_companion_match(const struct device *dev)
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);
}

/**
Expand Down

0 comments on commit e91a398

Please sign in to comment.