linux-acpi.vger.kernel.org archive mirror
 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>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Daniel Drake <drake@endlessm.com>,
	Jian-Hong Pan <jian-hong@endlessm.com>
Subject: [PATCH v2 4/6] ACPI: EC: Simplify acpi_ec_add()
Date: Wed, 04 Mar 2020 11:48:10 +0100	[thread overview]
Message-ID: <3645328.ZVAHyXvlRV@kreacher> (raw)
In-Reply-To: <2411774.6kdisLRoUK@kreacher>

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

First, notice that if the device ID in acpi_ec_add() is equal to
ACPI_ECDT_HID, boot_ec_is_ecdt must be set, because this means
that the device object passed to acpi_ec_add() comes from
acpi_ec_ecdt_start() which fails if boot_ec_is_ecdt is unset.
Accordingly, boot_ec_is_ecdt need not be set again in that case,
so drop that redundant update of it from the code.

Next, ec->handle must be a valid ACPI handle right before
returning 0 from acpi_ec_add(), because it either is the handle
of the device object passed to that function, or it is the boot EC
handle coming from acpi_ec_ecdt_start() which fails if it cannot
find a valid handle for the boot EC.  Moreover, the object with
that handle is regarded as a valid representation of the EC in all
cases, so there is no reason to avoid the _DEP list update walk if
that handle is the boot EC handle.  Accordingly, drop the dep_update
local variable from acpi_ec_add() and call acpi_walk_dep_device_list()
for ec->handle unconditionally before returning 0 from it.

Finally, the ec local variable in acpi_ec_add() need not be
initialized to NULL and the status local variable declaration
can be moved to the block in which it is used, so change the code
in accordance with these observations.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

-> v2: Reorder (previously [5/6]) and rebase.

---
 drivers/acpi/ec.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index 6f501d552e6e..116163add41b 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -1605,19 +1605,18 @@ static bool acpi_ec_ecdt_get_handle(acpi_handle *phandle)
 
 static int acpi_ec_add(struct acpi_device *device)
 {
-	struct acpi_ec *ec = NULL;
-	bool dep_update = true;
-	acpi_status status;
+	struct acpi_ec *ec;
 	int ret;
 
 	strcpy(acpi_device_name(device), ACPI_EC_DEVICE_NAME);
 	strcpy(acpi_device_class(device), ACPI_EC_CLASS);
 
 	if (!strcmp(acpi_device_hid(device), ACPI_ECDT_HID)) {
-		boot_ec_is_ecdt = true;
+		/* Fast path: this device corresponds to the boot EC. */
 		ec = boot_ec;
-		dep_update = false;
 	} else {
+		acpi_status status;
+
 		ec = acpi_ec_alloc();
 		if (!ec)
 			return -ENOMEM;
@@ -1660,10 +1659,9 @@ static int acpi_ec_add(struct acpi_device *device)
 	ret = !!request_region(ec->command_addr, 1, "EC cmd");
 	WARN(!ret, "Could not request EC cmd io port 0x%lx", ec->command_addr);
 
-	if (dep_update) {
-		/* Reprobe devices depending on the EC */
-		acpi_walk_dep_device_list(ec->handle);
-	}
+	/* Reprobe devices depending on the EC */
+	acpi_walk_dep_device_list(ec->handle);
+
 	acpi_handle_debug(ec->handle, "enumerated.\n");
 	return 0;
 
-- 
2.16.4





  parent reply	other threads:[~2020-03-04 10:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-27 22:19 [PATCH 0/6] ACPI: EC: Updates related to initialization Rafael J. Wysocki
2020-02-27 22:21 ` [PATCH 1/6] ACPI: EC: Avoid printing confusing messages in acpi_ec_setup() Rafael J. Wysocki
2020-02-27 22:21 ` [PATCH 2/6] ACPI: EC: Avoid passing redundant argument to functions Rafael J. Wysocki
2020-02-27 22:22 ` [PATCH 3/6] ACPI: EC: Drop AE_NOT_FOUND special case from ec_install_handlers() Rafael J. Wysocki
2020-02-27 22:23 ` [PATCH 4/6] ACPI: EC: Unify handling of event handler installation failures Rafael J. Wysocki
2020-02-27 22:23 ` [PATCH 5/6] ACPI: EC: Simplify acpi_ec_add() Rafael J. Wysocki
2020-02-27 22:24 ` [PATCH 6/6] ACPI: EC: Use fast path in acpi_ec_add() for DSDT boot EC Rafael J. Wysocki
2020-02-28  9:43 ` [PATCH 0/6] ACPI: EC: Updates related to initialization Daniel Drake
2020-03-02  5:53   ` Jian-Hong Pan
2020-03-02  9:55     ` Rafael J. Wysocki
2020-03-02 10:38     ` Rafael J. Wysocki
2020-03-02 11:45       ` Rafael J. Wysocki
2020-03-03  7:28         ` Jian-Hong Pan
2020-03-03  9:09           ` Rafael J. Wysocki
2020-03-03 22:23             ` Rafael J. Wysocki
2020-03-04  2:53               ` Jian-Hong Pan
2020-03-04  9:13                 ` Rafael J. Wysocki
2020-03-04 10:42 ` [PATCH v2 " Rafael J. Wysocki
2020-03-04 10:44   ` [PATCH v2 1/6] ACPI: EC: Avoid printing confusing messages in acpi_ec_setup() Rafael J. Wysocki
2020-03-04 10:45   ` [PATCH v2 2/6] ACPI: EC: Avoid passing redundant argument to functions Rafael J. Wysocki
2020-03-04 10:46   ` [PATCH v2 3/6] ACPI: EC: Drop AE_NOT_FOUND special case from ec_install_handlers() Rafael J. Wysocki
2020-03-04 10:48   ` Rafael J. Wysocki [this message]
2020-03-04 10:49   ` [PATCH v2 5/6] ACPI: EC: Use fast path in acpi_ec_add() for DSDT boot EC Rafael J. Wysocki
2020-03-04 10:52   ` [PATCH v2 6/6] ACPI: EC: Consolidate event handler installation code Rafael J. Wysocki

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=3645328.ZVAHyXvlRV@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=drake@endlessm.com \
    --cc=jian-hong@endlessm.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@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;
as well as URLs for NNTP newsgroup(s).