From patchwork Mon Jan 11 13:26:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksey Makarov X-Patchwork-Id: 8003801 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EDA82BEEE5 for ; Mon, 11 Jan 2016 13:35:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1294920279 for ; Mon, 11 Jan 2016 13:35:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B6CC20220 for ; Mon, 11 Jan 2016 13:35:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aIcbv-0002Br-1Q; Mon, 11 Jan 2016 13:34:15 +0000 Received: from mail-lb0-x22f.google.com ([2a00:1450:4010:c04::22f]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aIcUz-0002bY-Sj for linux-arm-kernel@lists.infradead.org; Mon, 11 Jan 2016 13:27:30 +0000 Received: by mail-lb0-x22f.google.com with SMTP id bc4so253230021lbc.2 for ; Mon, 11 Jan 2016 05:26:45 -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=yWbNWJDqzuun7xTD1fTg9TfF26l3zsryDEgmz82VDbw=; b=NMK+UbA1C2m3+OVCW1oeMc5HavV/GnDej3X7uTVkxRfKNwXdVk80of7uNgxTyEtQGn LmTo2qby+o8F52KZgVULbC1vuQqs0U5AD+ic9zgSB9YSZMIM6oPcHgKckwu+wEafoksR vn4jPBjwusa0nYQMehjagYG7Z7Y5WC+MaN8yY= 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=yWbNWJDqzuun7xTD1fTg9TfF26l3zsryDEgmz82VDbw=; b=Jw4/Zb5hGPQnm6AtyPUSUw19dgsD6Qlqo+ZFXZ5x2XepDtA54s5vg7tLxq6808Zr/q 9wj2Cpkd3LQC/wrPT3vm+ihvICse6PRWFfdwWGim07reXaexu7OjD9utMG0SPtmJ2K26 KAcFZzn0EjrR6cHdlaxi7AgyaKcRt5EyOSPcjuKMOaBJ2idxfyyaKqmhbvZkPDoox3FW wT/C+U35CxsHVN3TYDc+jF7gAXD7fM5crOYR+L8TJPijh554wQ/+d4B3HiBByYJvkMme WG70CmEgcLwmoZfQjVgIb85cJtk3xgz2/pBVmE7TgdTtwrQ4WuW4xs0an+T7I2w4d5Pl mhSA== X-Gm-Message-State: ALoCoQmngyiZepy5lBhoMCTv2eZ5QJ+rXDzxucSW1M6Y9M9d/pSK4kjaz18gmk8xi7dzFO0sUnMFj/OnJIQ1Y3CQp6cw7Te21g== X-Received: by 10.112.148.131 with SMTP id ts3mr42460608lbb.102.1452518803679; Mon, 11 Jan 2016 05:26:43 -0800 (PST) Received: from lemon.localdomain (host-2-60-215-78.pppoe.omsknet.ru. [2.60.215.78]) by smtp.gmail.com with ESMTPSA id xf10sm2418277lbb.23.2016.01.11.05.26.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 05:26:42 -0800 (PST) From: Aleksey Makarov To: linux-acpi@vger.kernel.org Subject: [PATCH v5 1/2] ACPI: introduce a function to find the first physical device Date: Mon, 11 Jan 2016 19:26:26 +0600 Message-Id: <1452518790-27053-2-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1452518790-27053-1-git-send-email-aleksey.makarov@linaro.org> References: <1452518790-27053-1-git-send-email-aleksey.makarov@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160111_052706_855163_CE1BC39F X-CRM114-Status: GOOD ( 15.74 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell King , Graeme Gregory , Greg Kroah-Hartman , Andy Shevchenko , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, Vladimir Zapolskiy , Aleksey Makarov , Shannon Zhao , linux-arm-kernel@lists.infradead.org, Len Brown MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Andy Shevchenko --- drivers/acpi/acpi_platform.c | 18 ++---------------- drivers/acpi/bus.c | 36 ++++++++++++++++++++++++------------ drivers/acpi/internal.h | 1 + 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index 296b7a1..c99aed0 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; @@ -83,21 +82,8 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) * 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); - } + if (adev->parent) + pdevinfo.parent = acpi_get_first_physical_node(adev->parent); 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..2048c69 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -478,24 +478,36 @@ 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_device_fix_parent - Get first physical node of an ACPI device + * @adev: ACPI device in question + */ +struct device *acpi_get_first_physical_node( + struct acpi_device *adev) { struct mutex *physical_node_lock = &adev->physical_node_lock; + struct device *ret = NULL; 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; - } + if (!list_empty(&adev->physical_node_list)) + ret = list_first_entry(&adev->physical_node_list, + struct acpi_device_physical_node, node)->dev; + mutex_unlock(physical_node_lock); - return adev; + + return ret; +} + +static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev, + const struct device *dev) +{ + const struct device *pdev = acpi_get_first_physical_node(adev); + + if (pdev && pdev == dev) + return adev; + + return 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