From: Duarte Silva <duartejcsilva@gmail.com>
To: linux-acpi@vger.kernel.org
Subject: Propose WMI patch
Date: Tue, 30 Sep 2008 12:06:35 +0100 [thread overview]
Message-ID: <200809301206.35983.duartejcsilva@gmail.com> (raw)
Hi,
I wanted to propose a ACPI-WMI API change. Instead of having, wmi_has_guid
returning a boolean, why not returning a acpi_status. It would allow extented
error handling, and it would look more ACPI style :)
diff --git a/drivers/acpi/wmi.c b/drivers/acpi/wmi.c
index cfe2c83..cdff9bf 100644
--- a/drivers/acpi/wmi.c
+++ b/drivers/acpi/wmi.c
@@ -194,14 +194,16 @@ static bool wmi_parse_guid(const u8 *src, u8 *dest)
return true;
}
-static bool find_guid(const char *guid_string, struct wmi_block **out)
+static acpi_status find_guid(const char *guid_string, struct wmi_block **out)
{
char tmp[16], guid_input[16];
struct wmi_block *wblock;
struct guid_block *block;
struct list_head *p;
- wmi_parse_guid(guid_string, tmp);
+ if (!wmi_parse_guid(guid_string, tmp))
+ return AE_BAD_PARAMETER;
+
wmi_swap_bytes(tmp, guid_input);
list_for_each(p, &wmi_blocks.list) {
@@ -211,10 +213,10 @@ static bool find_guid(const char *guid_string, struct
wmi_block **out)
if (memcmp(block->guid, guid_input, 16) == 0) {
if (out)
*out = wblock;
- return 1;
+ return AE_OK;
}
}
- return 0;
+ return AE_NOT_FOUND;
}
/*
@@ -241,8 +243,10 @@ u32 method_id, const struct acpi_buffer *in, struct
acpi_buffer *out)
union acpi_object params[3];
char method[4] = "WM";
- if (!find_guid(guid_string, &wblock))
- return AE_BAD_ADDRESS;
+ status = find_guid(guid_string, &wblock);
+
+ if (ACPI_FAILURE(status))
+ return status;
block = &wblock->gblock;
handle = wblock->handle;
@@ -303,7 +307,9 @@ struct acpi_buffer *out)
if (!guid_string || !out)
return AE_BAD_PARAMETER;
- if (!find_guid(guid_string, &wblock))
+ status = find_guid(guid_string, &wblock);
+
+ if (ACPI_FAILURE(status))
return AE_BAD_ADDRESS;
block = &wblock->gblock;
@@ -377,6 +383,7 @@ const struct acpi_buffer *in)
struct guid_block *block = NULL;
struct wmi_block *wblock = NULL;
acpi_handle handle;
+ acpi_status status;
struct acpi_object_list input;
union acpi_object params[2];
char method[4] = "WS";
@@ -384,7 +391,9 @@ const struct acpi_buffer *in)
if (!guid_string || !in)
return AE_BAD_DATA;
- if (!find_guid(guid_string, &wblock))
+ status = find_guid(guid_string, &wblock);
+
+ if (ACPI_FAILURE(status))
return AE_BAD_ADDRESS;
block = &wblock->gblock;
@@ -427,12 +436,14 @@ acpi_status wmi_install_notify_handler(const char *guid,
wmi_notify_handler handler, void *data)
{
struct wmi_block *block;
+ acpi_status status;
if (!guid || !handler)
return AE_BAD_PARAMETER;
- find_guid(guid, &block);
- if (!block)
+ status = find_guid(guid, &block);
+
+ if (ACPI_FAILURE(status))
return AE_NOT_EXIST;
if (block->handler)
@@ -453,12 +464,14 @@ EXPORT_SYMBOL_GPL(wmi_install_notify_handler);
acpi_status wmi_remove_notify_handler(const char *guid)
{
struct wmi_block *block;
+ acpi_status status;
if (!guid)
return AE_BAD_PARAMETER;
- find_guid(guid, &block);
- if (!block)
+ status = find_guid(guid, &block);
+
+ if (ACPI_FAILURE(status))
return AE_NOT_EXIST;
if (!block->handler)
@@ -507,15 +520,21 @@ acpi_status wmi_get_event_data(u32 event, struct
acpi_buffer *out)
EXPORT_SYMBOL_GPL(wmi_get_event_data);
/**
- * wmi_has_guid - Check if a GUID is available
+ * wmi_is_guid_present - Check if a GUID is available
* @guid_string: 36 char string of the form
fa50ff2b-f2e8-45de-83fa-65417f2f49ba
*
* Check if a given GUID is defined by _WDG
*/
-bool wmi_has_guid(const char *guid_string)
+acpi_status wmi_is_guid_present(const char *guid_string)
{
return find_guid(guid_string, NULL);
}
+EXPORT_SYMBOL_GPL(wmi_is_guid_present);
+
+bool wmi_has_guid(const char *guid_string)
+{
+ return ACPI_SUCCESS(find_guid(guid_string, NULL));
+}
EXPORT_SYMBOL_GPL(wmi_has_guid);
/*
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 702f79d..26f9c0a 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -198,6 +198,7 @@ extern acpi_status wmi_install_notify_handler(const char
*guid,
wmi_notify_handler handler, void *data);
extern acpi_status wmi_remove_notify_handler(const char *guid);
extern acpi_status wmi_get_event_data(u32 event, struct acpi_buffer *out);
+extern acpi_status wmi_is_guid_present(const char *guid);
extern bool wmi_has_guid(const char *guid);
#endif /* CONFIG_ACPI_WMI */
next reply other threads:[~2008-09-30 11:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-30 11:06 Duarte Silva [this message]
2008-09-30 11:13 ` Propose WMI patch Carlos Corbacho
2008-09-30 11:16 ` Carlos Corbacho
2008-09-30 11:29 ` Duarte Silva
2008-09-30 11:40 ` Carlos Corbacho
2008-09-30 13:05 ` Duarte Silva
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=200809301206.35983.duartejcsilva@gmail.com \
--to=duartejcsilva@gmail.com \
--cc=linux-acpi@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