public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Armin Wolf <W_Armin@gmx.de>
To: rafael@kernel.org, lenb@kernel.org
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/4] ACPI: EC: Make query handlers private
Date: Sat, 25 Feb 2023 12:51:43 +0100	[thread overview]
Message-ID: <20230225115144.31212-4-W_Armin@gmx.de> (raw)
In-Reply-To: <20230225115144.31212-1-W_Armin@gmx.de>

The ability for external modules to register query handlers
was broken for a long time due to having only a single user.
With the only user (sbshc) having been converted to use the
more robust query notifier call chain, the query handler
functionality can be made private. This also allows for some
cleanups.

Tested on a Acer Travelmate 4000WLMi.

Signed-off-by: Armin Wolf <W_Armin@gmx.de>
---
 drivers/acpi/ec.c       | 36 ++++++++----------------------------
 drivers/acpi/internal.h |  5 -----
 2 files changed, 8 insertions(+), 33 deletions(-)

diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index dc7860a825a0..825493d38a4f 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -143,9 +143,7 @@ MODULE_PARM_DESC(ec_no_wakeup, "Do not wake up from suspend-to-idle");

 struct acpi_ec_query_handler {
 	struct list_head node;
-	acpi_ec_query_func func;
 	acpi_handle handle;
-	void *data;
 	u8 query_bit;
 	struct kref kref;
 };
@@ -1082,9 +1080,7 @@ static void acpi_ec_put_query_handler(struct acpi_ec_query_handler *handler)
 	kref_put(&handler->kref, acpi_ec_query_handler_release);
 }

-int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
-			      acpi_handle handle, acpi_ec_query_func func,
-			      void *data)
+static int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, acpi_handle handle)
 {
 	struct acpi_ec_query_handler *handler =
 	    kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
@@ -1094,40 +1090,28 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,

 	handler->query_bit = query_bit;
 	handler->handle = handle;
-	handler->func = func;
-	handler->data = data;
 	mutex_lock(&ec->mutex);
 	kref_init(&handler->kref);
 	list_add(&handler->node, &ec->list);
 	mutex_unlock(&ec->mutex);
 	return 0;
 }
-EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);

-static void acpi_ec_remove_query_handlers(struct acpi_ec *ec,
-					  bool remove_all, u8 query_bit)
+static void acpi_ec_remove_query_handlers(struct acpi_ec *ec)
 {
 	struct acpi_ec_query_handler *handler, *tmp;
 	LIST_HEAD(free_list);

 	mutex_lock(&ec->mutex);
 	list_for_each_entry_safe(handler, tmp, &ec->list, node) {
-		if (remove_all || query_bit == handler->query_bit) {
-			list_del_init(&handler->node);
-			list_add(&handler->node, &free_list);
-		}
+		list_del_init(&handler->node);
+		list_add(&handler->node, &free_list);
 	}
 	mutex_unlock(&ec->mutex);
 	list_for_each_entry_safe(handler, tmp, &free_list, node)
 		acpi_ec_put_query_handler(handler);
 }

-void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit)
-{
-	acpi_ec_remove_query_handlers(ec, false, query_bit);
-}
-EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler);
-
 int register_acpi_ec_query_notifier(struct notifier_block *nb)
 {
 	return blocking_notifier_chain_register(&acpi_ec_chain_head, nb);
@@ -1151,12 +1135,8 @@ static void acpi_ec_event_processor(struct work_struct *work)

 	/* Allow notifier handlers to override query handlers */
 	ret = blocking_notifier_call_chain(&acpi_ec_chain_head, handler->query_bit, ec);
-	if (ret != NOTIFY_BAD) {
-		if (handler->func)
-			handler->func(handler->data);
-		else if (handler->handle)
-			acpi_evaluate_object(handler->handle, NULL, NULL, NULL);
-	}
+	if (ret != NOTIFY_BAD && handler->handle)
+		acpi_evaluate_object(handler->handle, NULL, NULL, NULL);

 	ec_dbg_evt("Query(0x%02x) stopped", handler->query_bit);

@@ -1402,7 +1382,7 @@ acpi_ec_register_query_methods(acpi_handle handle, u32 level,
 	status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer);

 	if (ACPI_SUCCESS(status) && sscanf(node_name, "_Q%x", &value) == 1)
-		acpi_ec_add_query_handler(ec, value, handle, NULL, NULL);
+		acpi_ec_add_query_handler(ec, value, handle);
 	return AE_OK;
 }

@@ -1587,7 +1567,7 @@ static void ec_remove_handlers(struct acpi_ec *ec)
 		clear_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags);
 	}
 	if (test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) {
-		acpi_ec_remove_query_handlers(ec, true, 0);
+		acpi_ec_remove_query_handlers(ec);
 		clear_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags);
 	}
 }
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index 6f41d42375ab..72ce5a9ba57f 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -202,17 +202,12 @@ extern struct acpi_ec *first_ec;

 /* If we find an EC via the ECDT, we need to keep a ptr to its context */
 /* External interfaces use first EC only, so remember */
-typedef int (*acpi_ec_query_func) (void *data);

 void acpi_ec_init(void);
 void acpi_ec_ecdt_probe(void);
 void acpi_ec_dsdt_probe(void);
 void acpi_ec_block_transactions(void);
 void acpi_ec_unblock_transactions(void);
-int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
-			      acpi_handle handle, acpi_ec_query_func func,
-			      void *data);
-void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit);

 int register_acpi_ec_query_notifier(struct notifier_block *nb);
 int unregister_acpi_ec_query_notifier(struct notifier_block *nb);
--
2.30.2


  parent reply	other threads:[~2023-02-25 11:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-25 11:51 [PATCH v2 0/4] ACPI: SBS: Fix various issues Armin Wolf
2023-02-25 11:51 ` [PATCH v2 1/4] ACPI: EC: Add query notifier support Armin Wolf
2023-02-25 11:51 ` [PATCH v2 2/4] ACPI: sbshc: Use ec query notifier call chain Armin Wolf
2023-02-25 11:51 ` Armin Wolf [this message]
2023-02-25 11:51 ` [PATCH v2 4/4] ACPI: SBS: Fix handling of Smart Battery Selectors Armin Wolf
2023-03-12 17:15 ` [PATCH v2 0/4] ACPI: SBS: Fix various issues Armin Wolf
2023-03-14 19:49   ` Rafael J. Wysocki
2023-03-14 23:04     ` Armin Wolf

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=20230225115144.31212-4-W_Armin@gmx.de \
    --to=w_armin@gmx.de \
    --cc=lenb@kernel.org \
    --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