Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1335338

[PATCH v6 1/2] ACPI: introduce a function to find the first physical device

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Aleksey Makarov <aleksey.makarov@linaro.org>
Newsgroups linux.kernel
Subject [PATCH v6 1/2] ACPI: introduce a function to find the first physical device
Date Tue, 16 Feb 2016 14:00:01 +0100
Message-ID <r2Not-7Xf-11@gated-at.bofh.it> (permalink)
References <r2Ct4-Dq-9@gated-at.bofh.it>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LuBMGZF+zzm3EH8XpUyulla3v6rM/SFICetIW5YEVgo=; b=UbD5B6jYVwsrY9X0d2hKhEn7GdD265tTRsqzQDiwTtLaLqlXPw+hDzBtVVjvs50WAn MR8Ok73g3xuznWv9LDaBQY76roB59WBYgVSrLs8o/wM3PGgWu+qguSJ2FKx3EcP9HLk0 xmlP0cSTVNiId4AdRH4tKU6K9uOEcpya0R3Ro=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LuBMGZF+zzm3EH8XpUyulla3v6rM/SFICetIW5YEVgo=; b=BPr0UxJWE084XLAZQs6tqlTNBIJOkYic3ede+cUwVAN+wGRGCJ1in6xbN440Qnoq2g EwU1SOwvLrN55rAThfq2p/fsQPsp8vbQy+5gcNa8CCTkKexF6i+s9GaepRGOtaa4bxeW eAQeg3XlUXBpmL5dy1PDfLDo6l/UJCNd+uXTrkWTDrUSgQBdP4qPeuTLCa2/s19v6YV8 BAH/u85+OkGnPovmqEx22N3Rsg/Bf/gh1qsoF/K6a7ZJ/bwePkIILAFgEuiR9AXHWIps i5FvI0DTFShQ221fHyTXhK/kmNL2IBuuKg2zmgMXXCMjX2aD5LPs7PwdiUDTT4dHGsvP 9gnw==
X-Gm-Message-State AG10YOQqyGmDONyzV3UVc8oZVw7Dgh4qduJykrSmulMlxc1QiJ9zgYtAEw5rYDcUG5PfnC/Q
X-Received by 10.25.32.65 with SMTP id g62mr4961676lfg.14.1455627501524; Tue, 16 Feb 2016 04:58:21 -0800 (PST)
X-Mailer git-send-email 2.7.1
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 110
Organization linux.* mail to news gateway
X-Original-Cc linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Aleksey Makarov <aleksey.makarov@linaro.org>, Graeme Gregory <graeme.gregory@linaro.org>, Russell King <linux@arm.linux.org.uk>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "Rafael J . Wysocki" <rjw@rjwysocki.net>, Shannon Zhao <shannon.zhao@linaro.org>, Andy Shevchenko <andy.shevchenko@gmail.com>, Vladimir Zapolskiy <vz@mleia.com>, Len Brown <lenb@kernel.org>
X-Original-Date Tue, 16 Feb 2016 15:52:38 +0300
X-Original-Message-ID <1455627160-10299-1-git-send-email-aleksey.makarov@linaro.org>
X-Original-References <2019009.4Y5n3ZF6bK@vostro.rjw.lan>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1335338

Show key headers only | View raw


Factor out the code that finds the first physical device
of a given ACPI device.  It is used in several places.

Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
---
 drivers/acpi/acpi_platform.c | 19 ++-----------------
 drivers/acpi/bus.c           | 26 ++++++++++++++++++++------
 drivers/acpi/internal.h      |  1 +
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index 296b7a1..c3af108 100644
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -43,7 +43,6 @@ static const struct acpi_device_id forbidden_id_list[] = {
 struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
 {
 	struct platform_device *pdev = NULL;
-	struct acpi_device *acpi_parent;
 	struct platform_device_info pdevinfo;
 	struct resource_entry *rentry;
 	struct list_head resource_list;
@@ -82,22 +81,8 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
 	 * attached to it, that physical device should be the parent of the
 	 * platform device we are about to create.
 	 */
-	pdevinfo.parent = NULL;
-	acpi_parent = adev->parent;
-	if (acpi_parent) {
-		struct acpi_device_physical_node *entry;
-		struct list_head *list;
-
-		mutex_lock(&acpi_parent->physical_node_lock);
-		list = &acpi_parent->physical_node_list;
-		if (!list_empty(list)) {
-			entry = list_first_entry(list,
-					struct acpi_device_physical_node,
-					node);
-			pdevinfo.parent = entry->dev;
-		}
-		mutex_unlock(&acpi_parent->physical_node_lock);
-	}
+	pdevinfo.parent = adev->parent ?
+		acpi_get_first_physical_node(adev->parent) : NULL;
 	pdevinfo.name = dev_name(&adev->dev);
 	pdevinfo.id = -1;
 	pdevinfo.res = resources;
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index a212cef..d27e0f4 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -478,24 +478,38 @@ 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)
+/**
+ * acpi_get_first_physical_node - Get first physical node of an ACPI device
+ * @adev:	ACPI device in question
+ *
+ * Return: First physical node of ACPI device @adev
+ */
+struct device *acpi_get_first_physical_node(struct acpi_device *adev)
 {
 	struct mutex *physical_node_lock = &adev->physical_node_lock;
+	struct device *phys_dev;
 
 	mutex_lock(physical_node_lock);
 	if (list_empty(&adev->physical_node_list)) {
-		adev = NULL;
+		phys_dev = 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;
+
+		phys_dev = node->dev;
 	}
 	mutex_unlock(physical_node_lock);
-	return adev;
+	return phys_dev;
+}
+
+static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev,
+						      const struct device *dev)
+{
+	const struct device *phys_dev = acpi_get_first_physical_node(adev);
+
+	return phys_dev && phys_dev == dev ? adev : NULL;
 }
 
 /**
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 11d87bf..ee9312ba 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -98,6 +98,7 @@ bool acpi_device_is_present(struct acpi_device *adev);
 bool acpi_device_is_battery(struct acpi_device *adev);
 bool acpi_device_is_first_physical_node(struct acpi_device *adev,
 					const struct device *dev);
+struct device *acpi_get_first_physical_node(struct acpi_device *adev);
 
 /* --------------------------------------------------------------------------
                      Device Matching and Notification
-- 
2.7.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [PATCH v6 1/2] ACPI: introduce a function to find the first physical device "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2016-02-16 02:20 +0100
  [PATCH v6 1/2] ACPI: introduce a function to find the first physical device Aleksey Makarov <aleksey.makarov@linaro.org> - 2016-02-16 14:00 +0100
    Re: [PATCH v6 1/2] ACPI: introduce a function to find the first physical device "Rafael J. Wysocki" <rjw@rjwysocki.net> - 2016-02-16 20:20 +0100

csiph-web