From: "Barnabás Pőcze" <pobrn@protonmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Xiaomeng Tong <xiam0nd.tong@gmail.com>,
Kees Cook <keescook@chromium.org>,
Jakob Koschel <jakobkoschel@gmail.com>,
Arnd Bergmann <arnd@arndb.de>
Subject: [RFC PATCH v1 2/2] platform/x86: wmi: use tlist for WMI blocks
Date: Fri, 11 Mar 2022 01:33:11 +0000 [thread overview]
Message-ID: <20220311013238.3387227-3-pobrn@protonmail.com> (raw)
In-Reply-To: <20220311013238.3387227-1-pobrn@protonmail.com>
tlist is a type-safer wrapper around the existing
`list_head` facilities. Use that to make the code
type-safer and shorter.
Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
---
drivers/platform/x86/wmi.c | 53 ++++++++++++++------------------------
1 file changed, 20 insertions(+), 33 deletions(-)
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 58a23a9adbef..4da968bda3dc 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -22,7 +22,7 @@
#include <linux/device.h>
#include <linux/init.h>
#include <linux/kernel.h>
-#include <linux/list.h>
+#include <linux/tlist.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/platform_device.h>
@@ -39,8 +39,6 @@ MODULE_AUTHOR("Carlos Corbacho");
MODULE_DESCRIPTION("ACPI-WMI Mapping Driver");
MODULE_LICENSE("GPL");
-static LIST_HEAD(wmi_block_list);
-
struct guid_block {
guid_t guid;
union {
@@ -75,6 +73,7 @@ struct wmi_block {
unsigned long flags;
};
+static TLIST_DEFINE(struct wmi_block, list, wmi_block_list);
/*
* If the GUID data block is marked as expensive, we must enable and
@@ -121,7 +120,6 @@ static struct platform_driver acpi_wmi_driver = {
static acpi_status find_guid(const char *guid_string, struct wmi_block **out)
{
guid_t guid_input;
- struct wmi_block *wblock;
if (!guid_string)
return AE_BAD_PARAMETER;
@@ -129,7 +127,7 @@ static acpi_status find_guid(const char *guid_string, struct wmi_block **out)
if (guid_parse(guid_string, &guid_input))
return AE_BAD_PARAMETER;
- list_for_each_entry(wblock, &wmi_block_list, list) {
+ tlist_for_each(&wmi_block_list, wblock) {
if (guid_equal(&wblock->gblock.guid, &guid_input)) {
if (out)
*out = wblock;
@@ -565,7 +563,6 @@ acpi_status wmi_install_notify_handler(const char *guid,
wmi_notify_handler handler,
void *data)
{
- struct wmi_block *block;
acpi_status status = AE_NOT_EXIST;
guid_t guid_input;
@@ -575,7 +572,7 @@ acpi_status wmi_install_notify_handler(const char *guid,
if (guid_parse(guid, &guid_input))
return AE_BAD_PARAMETER;
- list_for_each_entry(block, &wmi_block_list, list) {
+ tlist_for_each(&wmi_block_list, block) {
acpi_status wmi_status;
if (guid_equal(&block->gblock.guid, &guid_input)) {
@@ -605,7 +602,6 @@ EXPORT_SYMBOL_GPL(wmi_install_notify_handler);
*/
acpi_status wmi_remove_notify_handler(const char *guid)
{
- struct wmi_block *block;
acpi_status status = AE_NOT_EXIST;
guid_t guid_input;
@@ -615,7 +611,7 @@ acpi_status wmi_remove_notify_handler(const char *guid)
if (guid_parse(guid, &guid_input))
return AE_BAD_PARAMETER;
- list_for_each_entry(block, &wmi_block_list, list) {
+ tlist_for_each(&wmi_block_list, block) {
acpi_status wmi_status;
if (guid_equal(&block->gblock.guid, &guid_input)) {
@@ -652,9 +648,7 @@ EXPORT_SYMBOL_GPL(wmi_remove_notify_handler);
*/
acpi_status wmi_get_event_data(u32 event, struct acpi_buffer *out)
{
- struct wmi_block *wblock;
-
- list_for_each_entry(wblock, &wmi_block_list, list) {
+ tlist_for_each(&wmi_block_list, wblock) {
struct guid_block *gblock = &wblock->gblock;
if ((gblock->flags & ACPI_WMI_EVENT) && gblock->notify_id == event)
@@ -854,10 +848,8 @@ static int wmi_dev_match(struct device *dev, struct device_driver *driver)
static int wmi_char_open(struct inode *inode, struct file *filp)
{
const char *driver_name = filp->f_path.dentry->d_iname;
- struct wmi_block *wblock;
- struct wmi_block *next;
- list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
+ tlist_for_each(&wmi_block_list, wblock) {
if (!wblock->dev.dev.driver)
continue;
if (strcmp(driver_name, wblock->dev.dev.driver->name) == 0) {
@@ -1143,12 +1135,10 @@ static int wmi_create_device(struct device *wmi_bus_dev,
static void wmi_free_devices(struct acpi_device *device)
{
- struct wmi_block *wblock, *next;
-
/* Delete devices for all the GUIDs */
- list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
+ tlist_for_each_safe(&wmi_block_list, wblock) {
if (wblock->acpi_device == device) {
- list_del(&wblock->list);
+ tlist_remove(&wmi_block_list, wblock);
device_unregister(&wblock->dev.dev);
}
}
@@ -1156,9 +1146,7 @@ static void wmi_free_devices(struct acpi_device *device)
static bool guid_already_parsed(struct acpi_device *device, const guid_t *guid)
{
- struct wmi_block *wblock;
-
- list_for_each_entry(wblock, &wmi_block_list, list) {
+ tlist_for_each(&wmi_block_list, wblock) {
if (guid_equal(&wblock->gblock.guid, guid)) {
/*
* Because we historically didn't track the relationship
@@ -1182,7 +1170,7 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
{
struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
const struct guid_block *gblock;
- struct wmi_block *wblock, *next;
+ struct wmi_block *wblock;
union acpi_object *obj;
acpi_status status;
int retval = 0;
@@ -1232,7 +1220,7 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
continue;
}
- list_add_tail(&wblock->list, &wmi_block_list);
+ tlist_push_back(&wmi_block_list, wblock);
if (debug_event) {
wblock->handler = wmi_notify_debug;
@@ -1244,7 +1232,7 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
* Now that all of the devices are created, add them to the
* device tree and probe subdrivers.
*/
- list_for_each_entry_safe(wblock, next, &wmi_block_list, list) {
+ tlist_for_each_safe(&wmi_block_list, wblock) {
if (wblock->acpi_device != device)
continue;
@@ -1254,7 +1242,7 @@ static int parse_wdg(struct device *wmi_bus_dev, struct acpi_device *device)
&wblock->gblock.guid);
if (debug_event)
wmi_method_enable(wblock, false);
- list_del(&wblock->list);
+ tlist_remove(&wmi_block_list, wblock);
put_device(&wblock->dev.dev);
}
}
@@ -1308,21 +1296,20 @@ acpi_wmi_ec_space_handler(u32 function, acpi_physical_address address,
static void acpi_wmi_notify_handler(acpi_handle handle, u32 event,
void *context)
{
- struct wmi_block *wblock;
- bool found_it = false;
+ struct wmi_block *wblock = NULL;
- list_for_each_entry(wblock, &wmi_block_list, list) {
- struct guid_block *block = &wblock->gblock;
+ tlist_for_each(&wmi_block_list, b) {
+ struct guid_block *block = &b->gblock;
- if (wblock->acpi_device->handle == handle &&
+ if (b->acpi_device->handle == handle &&
(block->flags & ACPI_WMI_EVENT) &&
(block->notify_id == event)) {
- found_it = true;
+ wblock = b;
break;
}
}
- if (!found_it)
+ if (!wblock)
return;
/* If a driver is bound, then notify the driver. */
--
2.35.1
prev parent reply other threads:[~2022-03-11 1:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-11 1:32 [RFC PATCH v1 0/2] add type-safer list_head wrapper Barnabás Pőcze
2022-03-11 1:32 ` [RFC PATCH v1 1/2] list: " Barnabás Pőcze
2022-03-11 1:42 ` Linus Torvalds
2022-03-11 2:01 ` Linus Torvalds
2022-03-11 2:49 ` Barnabás Pőcze
2022-03-11 5:06 ` Linus Torvalds
2022-03-11 22:15 ` Barnabás Pőcze
2022-03-11 23:45 ` Linus Torvalds
2022-03-11 23:47 ` Linus Torvalds
2022-03-11 2:45 ` Barnabás Pőcze
2022-03-11 1:33 ` Barnabás Pőcze [this message]
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=20220311013238.3387227-3-pobrn@protonmail.com \
--to=pobrn@protonmail.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=jakobkoschel@gmail.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=xiam0nd.tong@gmail.com \
/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
all inboxes | Powered by JetHome®