public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Linux PM <linux-pm@vger.kernel.org>
Subject: [PATCH v1 3/5] ACPI: scan: Rearrange initialization of ACPI device objects
Date: Wed, 10 Aug 2022 18:16:33 +0200	[thread overview]
Message-ID: <1828627.tdWV9SEqCh@kreacher> (raw)
In-Reply-To: <12036348.O9o76ZdvQC@kreacher>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The initialization of ACPI device objects is split between
acpi_init_device_object() and __acpi_device_add() that initializes
the dev field in struct acpi_device.  The "release" function pointer
is passed to __acpi_device_add() for this reason.

However, that split is artificial and all of the initialization can
be carried out by acpi_init_device_object(), so rearrange the code
to that end.  In particular, make acpi_init_device_object() take the
"release" pointer as an argument, along with the "type" which is
related to it, instead of __acpi_device_add().

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/internal.h |    5 ++---
 drivers/acpi/power.c    |    5 +++--
 drivers/acpi/scan.c     |   27 ++++++++++++++-------------
 3 files changed, 19 insertions(+), 18 deletions(-)

Index: linux-pm/drivers/acpi/scan.c
===================================================================
--- linux-pm.orig/drivers/acpi/scan.c
+++ linux-pm/drivers/acpi/scan.c
@@ -673,8 +673,7 @@ static void acpi_store_pld_crc(struct ac
 	ACPI_FREE(pld);
 }
 
-static int __acpi_device_add(struct acpi_device *device,
-			     void (*release)(struct device *))
+static int __acpi_device_add(struct acpi_device *device)
 {
 	struct acpi_device_bus_id *acpi_device_bus_id;
 	int result;
@@ -730,11 +729,6 @@ static int __acpi_device_add(struct acpi
 
 	mutex_unlock(&acpi_device_lock);
 
-	if (device->parent)
-		device->dev.parent = &device->parent->dev;
-
-	device->dev.bus = &acpi_bus_type;
-	device->dev.release = release;
 	result = device_add(&device->dev);
 	if (result) {
 		dev_err(&device->dev, "Error registering device\n");
@@ -761,7 +755,7 @@ err_unlock:
 	return result;
 }
 
-int acpi_device_add(struct acpi_device *adev, void (*release)(struct device *))
+int acpi_device_add(struct acpi_device *adev)
 {
 	int ret;
 
@@ -769,7 +763,7 @@ int acpi_device_add(struct acpi_device *
 	if (ret)
 		return ret;
 
-	return __acpi_device_add(adev, release);
+	return __acpi_device_add(adev);
 }
 
 /* --------------------------------------------------------------------------
@@ -1776,12 +1770,19 @@ static bool acpi_device_enumeration_by_p
 }
 
 void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
-			     int type)
+			     int type, void (*release)(struct device *))
 {
+	struct acpi_device *parent = acpi_find_parent_acpi_dev(handle);
+
 	INIT_LIST_HEAD(&device->pnp.ids);
 	device->device_type = type;
 	device->handle = handle;
-	device->parent = acpi_find_parent_acpi_dev(handle);
+	if (parent) {
+		device->parent = parent;
+		device->dev.parent = &parent->dev;
+	}
+	device->dev.release = release;
+	device->dev.bus = &acpi_bus_type;
 	fwnode_init(&device->fwnode, &acpi_device_fwnode_ops);
 	acpi_set_device_status(device, ACPI_STA_DEFAULT);
 	acpi_device_get_busid(device);
@@ -1835,7 +1836,7 @@ static int acpi_add_single_object(struct
 	if (!device)
 		return -ENOMEM;
 
-	acpi_init_device_object(device, handle, type);
+	acpi_init_device_object(device, handle, type, acpi_device_release);
 	/*
 	 * Getting the status is delayed till here so that we can call
 	 * acpi_bus_get_status() and use its quirk handling.  Note that
@@ -1865,7 +1866,7 @@ static int acpi_add_single_object(struct
 		mutex_unlock(&acpi_dep_list_lock);
 
 	if (!result)
-		result = __acpi_device_add(device, acpi_device_release);
+		result = __acpi_device_add(device);
 
 	if (result) {
 		acpi_device_release(&device->dev);
Index: linux-pm/drivers/acpi/internal.h
===================================================================
--- linux-pm.orig/drivers/acpi/internal.h
+++ linux-pm/drivers/acpi/internal.h
@@ -102,10 +102,9 @@ struct acpi_device_bus_id {
 	struct list_head node;
 };
 
-int acpi_device_add(struct acpi_device *device,
-		    void (*release)(struct device *));
 void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
-			     int type);
+			     int type, void (*release)(struct device *));
+int acpi_device_add(struct acpi_device *device);
 int acpi_device_setup_files(struct acpi_device *dev);
 void acpi_device_remove_files(struct acpi_device *dev);
 void acpi_device_add_finalize(struct acpi_device *device);
Index: linux-pm/drivers/acpi/power.c
===================================================================
--- linux-pm.orig/drivers/acpi/power.c
+++ linux-pm/drivers/acpi/power.c
@@ -944,7 +944,8 @@ struct acpi_device *acpi_add_power_resou
 		return NULL;
 
 	device = &resource->device;
-	acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER);
+	acpi_init_device_object(device, handle, ACPI_BUS_TYPE_POWER,
+				acpi_release_power_resource);
 	mutex_init(&resource->resource_lock);
 	INIT_LIST_HEAD(&resource->list_node);
 	INIT_LIST_HEAD(&resource->dependents);
@@ -968,7 +969,7 @@ struct acpi_device *acpi_add_power_resou
 	pr_info("%s [%s]\n", acpi_device_name(device), acpi_device_bid(device));
 
 	device->flags.match_driver = true;
-	result = acpi_device_add(device, acpi_release_power_resource);
+	result = acpi_device_add(device);
 	if (result)
 		goto err;
 




  parent reply	other threads:[~2022-08-10 16:24 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-10 16:11 [PATCH v1 0/5] ACPI: Device enumeration rearrangements and parent field elimination Rafael J. Wysocki
2022-08-10 16:14 ` [PATCH v1 1/5] ACPI: Rename acpi_bus_get/put_acpi_device() Rafael J. Wysocki
2022-08-10 16:30   ` Guenter Roeck
2022-08-10 16:15 ` [PATCH v1 2/5] ACPI: scan: Rename acpi_bus_get_parent() and rearrange it Rafael J. Wysocki
2022-08-12 13:08   ` Punit Agrawal
2022-08-10 16:16 ` Rafael J. Wysocki [this message]
2022-08-10 16:17 ` [PATCH v1 4/5] ACPI: scan: Eliminate __acpi_device_add() Rafael J. Wysocki
2022-08-10 16:23 ` [PATCH v1 5/5][RFT] ACPI: Drop parent field from struct acpi_device Rafael J. Wysocki
2022-08-10 16:33   ` Mark Brown
2022-08-10 17:10   ` Mika Westerberg
2022-08-12 15:14   ` Wei Liu
2022-08-24 16:59   ` [PATCH v2 5/5] " Rafael J. Wysocki
2022-08-24 18:23     ` Andy Shevchenko
2022-08-24 18:34       ` Rafael J. Wysocki
2022-08-27 13:19     ` Hanjun Guo
2022-08-29 15:54       ` Rafael J. Wysocki
2022-08-30 21:29     ` Michael Kelley (LINUX)
2022-08-12 13:11 ` [PATCH v1 0/5] ACPI: Device enumeration rearrangements and parent field elimination Punit Agrawal
2022-08-23 16:25   ` Rafael J. Wysocki
2022-08-29 15:21 ` [PATCH v1] ACPI: PM: Fix NULL argument handling in acpi_device_get/set_power() Rafael J. Wysocki
2022-08-29 15:53 ` [PATCH v1] ACPI: Drop redundant acpi_dev_parent() header Rafael J. Wysocki
2022-08-30  2:17   ` Hanjun Guo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1828627.tdWV9SEqCh@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox