From patchwork Tue Feb 16 12:52:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 62019 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1646881lbl; Tue, 16 Feb 2016 04:58:26 -0800 (PST) X-Received: by 10.98.69.1 with SMTP id s1mr8945651pfa.120.1455627506597; Tue, 16 Feb 2016 04:58:26 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ey9si51162323pab.123.2016.02.16.04.58.26; Tue, 16 Feb 2016 04:58:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932124AbcBPM6Y (ORCPT + 6 others); Tue, 16 Feb 2016 07:58:24 -0500 Received: from mail-lf0-f51.google.com ([209.85.215.51]:35458 "EHLO mail-lf0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932114AbcBPM6X (ORCPT ); Tue, 16 Feb 2016 07:58:23 -0500 Received: by mail-lf0-f51.google.com with SMTP id l143so108154540lfe.2 for ; Tue, 16 Feb 2016 04:58:22 -0800 (PST) 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=cye2YLX04/KTrL87y5+eKyv4WEnlzRyec6AkYu8LyLQr7+H20JsLJG+g6Nylk+CkRH xF8+K7qquP0/aVWBkFT5JHjhtXVYP8BjMG9LKTDDEQJFl3lbOrdjY+QKwSFPfzSC2KbP Zzspk/Txpa9xsLoBXfSvq19nky5ZsoKstfmN+Lcl9ha6oZMy5bo1ONIZ7n6CxolGWFgu P7T1elkhj3PnA4B6jOUBQarW7o3yXLDenJ/alN/bE7LR0mhzdonETUQk9c4TxN1hVorN cGB3T5Nw77L6j5T9nkHI47FU6ljt5BmtEAIqwgHyznZ+x5onHJpjGuxbe6K8+usYxpCT JPFw== X-Gm-Message-State: AG10YOTli18qzi4eUnuCaB9nvPPHnBRAvqdxsHkl3ytoJNCaJfPVB47fcEpn0P/XMxiJnkkl X-Received: by 10.25.32.65 with SMTP id g62mr4961676lfg.14.1455627501524; Tue, 16 Feb 2016 04:58:21 -0800 (PST) Received: from turnip.localdomain (nivc-213.auriga.ru. [80.240.102.213]) by smtp.gmail.com with ESMTPSA id xo4sm4267765lbb.27.2016.02.16.04.58.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Feb 2016 04:58:20 -0800 (PST) From: Aleksey Makarov To: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Aleksey Makarov , Graeme Gregory , Russell King , Greg Kroah-Hartman , "Rafael J . Wysocki" , Shannon Zhao , Andy Shevchenko , Vladimir Zapolskiy , Len Brown Subject: [PATCH v6 1/2] ACPI: introduce a function to find the first physical device Date: Tue, 16 Feb 2016 15:52:38 +0300 Message-Id: <1455627160-10299-1-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.1 In-Reply-To: <2019009.4Y5n3ZF6bK@vostro.rjw.lan> References: <2019009.4Y5n3ZF6bK@vostro.rjw.lan> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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 --- drivers/acpi/acpi_platform.c | 19 ++----------------- drivers/acpi/bus.c | 26 ++++++++++++++++++++------ drivers/acpi/internal.h | 1 + 3 files changed, 23 insertions(+), 23 deletions(-) -- 2.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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