From patchwork Wed Jan 20 14:29: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: 60037 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp3207256lbb; Wed, 20 Jan 2016 06:30:28 -0800 (PST) X-Received: by 10.66.242.17 with SMTP id wm17mr52144248pac.155.1453300227817; Wed, 20 Jan 2016 06:30:27 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g15si55511265pfg.147.2016.01.20.06.30.27; Wed, 20 Jan 2016 06:30:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934259AbcATOa0 (ORCPT + 29 others); Wed, 20 Jan 2016 09:30:26 -0500 Received: from mail-lb0-f176.google.com ([209.85.217.176]:34207 "EHLO mail-lb0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934147AbcATO3p (ORCPT ); Wed, 20 Jan 2016 09:29:45 -0500 Received: by mail-lb0-f176.google.com with SMTP id cl12so6065113lbc.1 for ; Wed, 20 Jan 2016 06:29:44 -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=FD73j3WdYzPdS8r2mpxL4kWaq6G4isy/WYlVNx8OXrM=; b=UPjN/I8NynwZbXYhkhkEjoqp+pY7DnVfiR/q2JYlPmQs9mP00tzCuS8eP+JcuMcGAf 7LBpubUeCYwk0DQxfBv/+yelhhKyWNj3Zbw8xxDFDfXaHy76axhQFmKYC13D/j9Lg6fS IrdLJYI23JxxCW1qLk2iPWchnzOQQXrBP/Ty0= 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=FD73j3WdYzPdS8r2mpxL4kWaq6G4isy/WYlVNx8OXrM=; b=FlQWYNuB5pHEZgC/93fya89xsYZR6zUmduwbZy1pf44iq4ARXcHqaveX+nlPLqS3oa 1eH7UveHg2j1dAeYXoRBAXntNknyrCPCaDXOiiXZi2zGL3rEXKWjVdoVLLpW52HM4JVA txbWWTVUGHwyiJRMoI86SdneZw2wyKv+97ILYCOrIRsjZBHp9GlXLhRg6eIvyV0TdkAF qipn5Je9GF9vyMzWC5jc82Z2kBNryup13fu5dDHT4WvnF6ShxHx/ekJJ2AFydlshn6KK fpy0RkwzV17CvAFN3WGhSAEQu9LqarDYE6s+FeL6ZIg8SX48Fe7DGLehTqgrKRU1GKME XQvw== X-Gm-Message-State: ALoCoQmqUhTVFaHq0kDjsAtaauTlGADkAKeTl1Whr0Q3Pp+9lrAXMkABoHTpZPQmb9nwmou7UakHObbrCAIEoOAd71yv3D1xwg== X-Received: by 10.112.17.70 with SMTP id m6mr13417757lbd.130.1453300183804; Wed, 20 Jan 2016 06:29:43 -0800 (PST) Received: from lemon.localdomain (host-2-60-44-52.pppoe.omsknet.ru. [2.60.44.52]) by smtp.gmail.com with ESMTPSA id q8sm4683121lbf.24.2016.01.20.06.29.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Jan 2016 06:29:43 -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: Wed, 20 Jan 2016 20:29:26 +0600 Message-Id: <1453300171-25473-2-git-send-email-aleksey.makarov@linaro.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1453300171-25473-1-git-send-email-aleksey.makarov@linaro.org> References: <1453300171-25473-1-git-send-email-aleksey.makarov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Factor out the code that finds the first physical device of a given ACPI device. It is used in several places. Reviewed-by: Andy Shevchenko Signed-off-by: Aleksey Makarov --- drivers/acpi/acpi_platform.c | 19 ++----------------- drivers/acpi/bus.c | 33 ++++++++++++++++++++++----------- drivers/acpi/internal.h | 1 + 3 files changed, 25 insertions(+), 28 deletions(-) -- 2.7.0 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..832b26d 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -478,24 +478,35 @@ 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 *node = NULL; mutex_lock(physical_node_lock); - if (list_empty(&adev->physical_node_list)) { - adev = NULL; - } else { - const struct acpi_device_physical_node *node; + if (!list_empty(&adev->physical_node_list)) node = list_first_entry(&adev->physical_node_list, - struct acpi_device_physical_node, node); - if (node->dev != dev) - adev = NULL; - } + struct acpi_device_physical_node, node)->dev; + mutex_unlock(physical_node_lock); - return adev; + + return node; +} + +static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev, + const struct device *dev) +{ + const struct device *node = acpi_get_first_physical_node(adev); + + if (node && node == 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