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: 59491 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2108329lbb; Mon, 11 Jan 2016 05:26:57 -0800 (PST) X-Received: by 10.67.4.100 with SMTP id cd4mr107753541pad.59.1452518816978; Mon, 11 Jan 2016 05:26:56 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 73si28589135pfl.31.2016.01.11.05.26.56; Mon, 11 Jan 2016 05:26:56 -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 S1760220AbcAKN0s (ORCPT + 29 others); Mon, 11 Jan 2016 08:26:48 -0500 Received: from mail-lb0-f173.google.com ([209.85.217.173]:34641 "EHLO mail-lb0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759651AbcAKN0p (ORCPT ); Mon, 11 Jan 2016 08:26:45 -0500 Received: by mail-lb0-f173.google.com with SMTP id cl12so36563234lbc.1 for ; Mon, 11 Jan 2016 05:26: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=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=eAqE6lsosC5f7WxtuCLpr4eNPfJvtW8ZWtal5qKMCZN5b4oDsXYOVfh4fZjbdL8F13 vzADd4YsIQ3XYTC91fAqiVdRlEJHIGWGHfaOcoUsIoR2yzd2UXxSYeWiOgYIyfTQoYCU yoc4DE2mNeRgRirwnqYSt7TaUjT1gXKQalRIl/zp2mDF7rt3VVCzIJK1XYBXngcuN8fw iX95ebOwfeogO0qRsatr9LVmBaOOvc10b0F/s6M5cVId127AWsj2tem5V7DaT0v6wMlj 1utnoE/uU69KHjiu+7nQ7wTgM8+Tv8JVf1/JpQiP3mtEx6cV5x4w+ohhECnyXg5+/FAJ tcXg== X-Gm-Message-State: ALoCoQmuShlQUHYkyXx7rBRyKCGdYtYkzsNHYaoEYaa7IvQRNU88VqG1x2Tgj1qif0x4LMYKCS95uKBRThvmEvdrHSW93LHcTQ== 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 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 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> 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. Signed-off-by: Aleksey Makarov --- drivers/acpi/acpi_platform.c | 18 ++---------------- drivers/acpi/bus.c | 36 ++++++++++++++++++++++++------------ drivers/acpi/internal.h | 1 + 3 files changed, 27 insertions(+), 28 deletions(-) -- 2.7.0 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