Skip to content

Commit 475b087

Browse files
computersforpeacebleungatchromium
authored andcommitted
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: Brian Norris <briannorris@chromium.org> Acked-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: Benson Leung <bleung@chromium.org>
1 parent 6510223 commit 475b087

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event)
580580

581581
if (!ec_dev->mkbp_event_supported) {
582582
ret = get_keyboard_state_event(ec_dev);
583-
if (ret < 0)
583+
if (ret <= 0)
584584
return ret;
585585

586586
if (wake_event)
@@ -590,7 +590,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event)
590590
}
591591

592592
ret = get_next_event(ec_dev);
593-
if (ret < 0)
593+
if (ret <= 0)
594594
return ret;
595595

596596
if (wake_event) {

include/linux/mfd/cros_ec.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,9 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev);
317317
* @wake_event: Pointer to a bool set to true upon return if the event might be
318318
* treated as a wake event. Ignored if null.
319319
*
320-
* Return: 0 on success or negative error code.
320+
* Return: negative error code on errors; 0 for no data; or else number of
321+
* bytes received (i.e., an event was retrieved successfully). Event types are
322+
* written out to @ec_dev->event_data.event_type on success.
321323
*/
322324
int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event);
323325

@@ -329,7 +331,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev, bool *wake_event);
329331
* events raised and call the functions in the ec notifier. This function
330332
* is a helper to know which events are raised.
331333
*
332-
* Return: 0 on success or negative error code.
334+
* Return: 0 on error or non-zero bitmask of one or more EC_HOST_EVENT_*.
333335
*/
334336
u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
335337

0 commit comments

Comments
 (0)