Commit 475b0873 authored by Brian Norris's avatar Brian Norris Committed by Benson Leung

platform/chrome: straighten out cros_ec_get_{next,host}_event() error codes

cros_ec_get_next_event() is documented to return 0 for success and
negative for errors. It currently returns negative for some errors, and
non-negative (number of bytes received) for success (including some "no
data available" responses as zero). This mostly works out OK, because the
callers were more or less ignoring the documentation, and only treating
positive values as success (and indepdently checking the modification of
'wakeup').

Let's button this up by avoiding pretending to handle event/wakeup
distinctions when no event info was retrieved (i.e., returned 0 bytes).
And fix the documentation of cros_ec_get_host_event() and
cros_ec_get_next_event() to accurately describe their behavior.
Signed-off-by: default avatarBrian Norris <briannorris@chromium.org>
Acked-by: default avatarLee Jones <lee.jones@linaro.org>
Signed-off-by: default avatarBenson Leung <bleung@chromium.org>
parent 65102238
...@@ -580,7 +580,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event) ...@@ -580,7 +580,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event)
if (!ec_dev->mkbp_event_supported) { if (!ec_dev->mkbp_event_supported) {
ret = get_keyboard_state_event(ec_dev); ret = get_keyboard_state_event(ec_dev);
if (ret < 0) if (ret <= 0)
return ret; return ret;
if (wake_event) if (wake_event)
...@@ -590,7 +590,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event) ...@@ -590,7 +590,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event)
} }
ret = get_next_event(ec_dev); ret = get_next_event(ec_dev);
if (ret < 0) if (ret <= 0)
return ret; return ret;
if (wake_event) { if (wake_event) {
......
...@@ -317,7 +317,9 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev); ...@@ -317,7 +317,9 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev);
* @wake_event: Pointer to a bool set to true upon return if the event might be * @wake_event: Pointer to a bool set to true upon return if the event might be
* treated as a wake event. Ignored if null. * treated as a wake event. Ignored if null.
* *
* Return: 0 on success or negative error code. * Return: negative error code on errors; 0 for no data; or else number of
* bytes received (i.e., an event was retrieved successfully). Event types are
* written out to @ec_dev->event_data.event_type on success.
*/ */
int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event); int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event);
...@@ -329,7 +331,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event); ...@@ -329,7 +331,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event);
* events raised and call the functions in the ec notifier. This function * events raised and call the functions in the ec notifier. This function
* is a helper to know which events are raised. * is a helper to know which events are raised.
* *
* Return: 0 on success or negative error code. * Return: 0 on error or non-zero bitmask of one or more EC_HOST_EVENT_*.
*/ */
u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev); u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment